大多数基于文档的 Mac OS X 应用程序都有一个文件 ---> 打开最近的...菜单项。这是您使用该程序打开的最近文件的列表。删除所有项目很容易;只需选择清除菜单。
但是,有时您可能只想删除一两个项目而不是所有项目,例如不再存在的文件,或者您不想再看到的文件。如何从“打开最近”列表中删除单个项目,而不删除任何其他内容?

Dan*_*eck 14
在大多数应用程序中,特定于应用程序的最近文档位于名为:
~/Library/Preferences/com.company.application.LSSharedFileList.plist
要在终端中列出所有这些文件,请输入以下内容:
ls -Ad Library/Preferences/* | grep LSSharedFileList
Run Code Online (Sandbox Code Playgroud)
在 Mac OS X 10.6 上,这些文件(通常)是二进制格式。
使用属性列表编辑器 (Apple Developer Tools / Xcode 3) 或 Xcode 4 来查看和编辑它们。
它们在应用程序启动时被重新读取,而不是在它运行时。您需要在编辑此文件时关闭应用程序。
我想我很无聊...
#!/usr/bin/env bash
mode=$2
if [ -z "$mode" ] ; then
echo "Usage:"
echo "$0 <filename> ls - list recent file entries in specified *.LSSharedFileList.plist"
echo "$0 <filename> rm <idx> - remove recent file entry with given index from specified plist"
exit 1
fi
if [ "$mode" != "ls" ] && [ "$mode" != "rm" ] ; then
echo "second argument must be one of [ls, rm]"
exit 1
fi
file=$1
if [ -z $file ] ; then
echo "Need argument (recent items plist file)!"
exit 1
fi
if [ ! -f $file ] ; then
echo "File $file does not exist!"
exit 1
fi
if [ "$mode" = "ls" ] ; then
i=0
cont=1
while [ $cont ] ; do
recentfilename=$( /usr/libexec/PlistBuddy -c "Print RecentDocuments:CustomListItems:$i:Name" $file 2>/dev/null )
if [ "$?" -ne "0" ] ; then
cont=
else
echo "$i - $recentfilename"
i=$(( $i + 1 ))
fi
done
fi
if [ "$mode" = "rm" ] ; then
i=$3
if [[ $i =~ ^-?[0-9]+$ ]] ; then
# argument is integer
$( /usr/libexec/PlistBuddy -c "Delete RecentDocuments:CustomListItems:$i" $file )
else
echo "Expected integer, got $i as third argument"
exit 1
fi
fi
Run Code Online (Sandbox Code Playgroud)
用法:
$ ./editrecent.sh
Usage:
./editrecent.sh <filename> ls - list recent file entries in specified *.LSSharedFileList.plist
./editrecent.sh <filename> rm <idx> - remove recent file entry with given index from specified plist
$ ./editrecent.sh Library/Preferences/com.macromates.textmate.LSSharedFileList.plist ls
0 - rcd
1 - artifactory.sh
2 - py.py
3 - iTunes Music Library.xml
4 - iTunes Library.xml
5 - gradle-proxy-support.diff
6 - DefaultGradlePropertiesLoader.java
7 - DefaultGradlePropertiesLoader-proxy.java
8 - gradle-proxy-support.patch
9 - DefaultKeyBinding.dict
10 - DefaultKeyBindings.dict
$ ./editrecent.sh Library/Preferences/com.macromates.textmate.LSSharedFileList.plist rm 3
$ ./editrecent.sh Library/Preferences/com.macromates.textmate.LSSharedFileList.plist ls
0 - rcd
1 - artifactory.sh
2 - py.py
3 - iTunes Library.xml
4 - gradle-proxy-support.diff
5 - DefaultGradlePropertiesLoader.java
6 - DefaultGradlePropertiesLoader-proxy.java
7 - gradle-proxy-support.patch
8 - DefaultKeyBinding.dict
9 - DefaultKeyBindings.dict
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13536 次 |
| 最近记录: |