Hi James
A very 'high end user' approach to use the script could be:
1. in the shell, create a text file and open TextEdit:
$ touch fhistory.txt
$ open fhstory.txt
2. paste the script from above into this file and then save and close (make sure you start with the '#! /bin/sh line' and end with the 'fi' on the last line)
3. back in the shell rename the file and make it executable:
$ mv fhistory.txt fhistory.sh
$ chmod +x fhistory.sh
4. use the script with these variations:
Display the history:
$ fhistory.sh TextEdit
Delete and disable the history:
$ fhistory.sh -d TextEdit
Enable the history:
$ fhistory.sh -e TextEdit
Hope this helps :-)
The script previously posted has a small typo!!! Use this one here:
#! /bin/sh
#
# fhistory.sh
#
# Written in 2011 by Marcel Egloff
#
# A basic tool to display, enable or disable the (global) recent file history for an individual Application
#
# Use it at your own risk and do with it what you want as long as you don't blame me!
#
PROGRAM=`basename $0`
USAGE=`printf "%%i-$PROGRAM: usage: %s [-ed] Application\n" $PROGRAM`
enable=0
disable=0
while getopts ed opt; do
case $opt in
e) enable=1;;
d) disable=1;;
?) echo $USAGE
exit 1;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -eq 1 ]; then
application=$1
else
echo $USAGE
exit 1
fi
extension=`echo $application | awk -F. '{ print $NF }'`
if [ "$extension" != "app" ]; then
application="$application.app"
fi
dir=`dirname $application`
if [ "$dir" != "." ]; then
path=$application
else
path=`find ~/Applications/* -name "$application"`
if [ -z "$path" ]; then
path=`find /Applications/* -prune -name "$application"`
fi
fi
if [ -n "$path" ]; then
if [ -f "$path/Contents/Info.plist" ]; then
if [ -x /usr/libexec/PlistBuddy ]; then
identifier=`/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" "$path/Contents/Info.plist"`
else
printf "%%i-$PROGRAM: PlistBuddy not found in /usr/libexec - aborting\n"
exit 1
fi
else
printf "%%i-$PROGRAM: Info.plist not found in '$path/Contents' - aborting\n"
exit 1
fi
else
printf "%%i-$PROGRAM: Application '$application' not found\n"
exit 1
fi
if [ -n "$identifier" ]; then
echo "Path: $path"
echo "Identifier: $identifier"
if [ $enable -eq 0 -a $disable -eq 0 ]; then
echo
max=`defaults read $identifier.LSSharedFileList RecentDocuments 2> /dev/null | grep 'MaxAmount' | sed 's:[^0-9]*::g'`
if [ -z "$max" ]; then
echo "No history found - system defaults will be applied."
else
echo "Maximum number of files in history: $max"
echo
n=1
defaults read $identifier.LSSharedFileList RecentDocuments 2> /dev/null | grep 'Name[ ]*=' | awk -F'"' '{ print $2 }' | while read file; do
printf "%2d. %s\n" $n "$file"
n=$[n+1]
done
fi
elif [ $enable -eq 0 ]; then
defaults write $identifier NSRecentDocumentsLimit 0
defaults delete $identifier.LSSharedFileList RecentDocuments
defaults write $identifier.LSSharedFileList RecentDocuments -dict-add MaxAmount 0
printf "%%i-$PROGRAM: file history disabled\n"
else
read line
defaults delete $identifier NSRecentDocumentsLimit
read line
defaults write $identifier.LSSharedFileList RecentDocuments -dict-add MaxAmount 10 # should supply the system wide default here
printf "%%i-$PROGRAM: file history enabled\n"
fi
else
printf "%%i-$PROGRAM: Application identifier not found\n"
fi