Re: clear apple menu's recent items script
Re: clear apple menu's recent items script
- Subject: Re: clear apple menu's recent items script
- From: kai <email@hidden>
- Date: Sun, 16 Apr 2006 20:04:21 +0100
On 16 Apr 2006, at 04:06, Irwin Poche wrote:
Thank you John, that's an interesting article. I played around
with the defaults command but as you suggested it does not appear
to work for what's shown in the Recent Items menu.
What does work is to UI script the Apple > Recent Items > Clear
Menu to clear all Apps, Docs, and Servers. I want to clear only
the Docs and Apps. This script clears those items on the menu and
also causes ~/Library/Preferences/com.apple.recentitems.pref to be
rewritten so that the old Doc and App data has also been removed
from the file.
While previous Mac OS versions maintained recent items as alias
files, the current system uses the plist file mentioned. However, it
seems the settings in the file are loaded at login into memory - and
modified dynamically there. The plist file is updated periodically
(usually about a minute after a new application, document, etc. is
opened) - but it's essentially a one-way street. So if the file
settings are altered via the back door (or even if the entire file is
trashed), the contents of the Recent Items menu will remain unchanged.
As Irwin has noted, the only way to change the dynamic settings seems
to be through UI access - either through the 'Clear Menu' menu item
itself, or via System Preferences. Either method should modify the
contents of both the menu and the file. (I hadn't realised, until his
last message, that Irwin wanted to remove menu items selectively -
otherwise I might have jumped in sooner with this.)
To demonstrate this behaviour, try running the following script. On
the first run, it should show any items currently listed in the
'Recent Items' menu. At the same time, it will clear those items in
the plist file (but won't affect the menu). If the script is run
again immediately, it will confirm that the plist file contains no
recent items.
When run yet again, the script should remain in the outer repeat loop
until the contents of the file are changed - for which you'll need to
open up a new application or document. As mentioned earlier, it may
take a minute or so for any change to be registered - so be prepared
for a short wait. (If only a new application is opened during this
time, then only the plist file's applications should be restored &
updated. Similarly, opening the document of an already-open
application should affect only the plist file's listed documents.)
The results support the view that, while the plist file is used to
load any previous settings at login, its purpose thereafter seems to
be primarily for storing the latest settings - in readiness for the
next login.
--------
property typeList : {"Servers", "Applications", "Documents"}
property currList : {missing value, missing value, missing value}
set itemCount to 0
set p to POSIX path of (path to preferences) &
"com.apple.recentitems.plist"
tell application "System Events" to tell property list file p to repeat
set l to typeList's items
repeat with i in l
tell property list item "CustomListItems" of property list item i
to set {value, i's contents} ¬
to {{}, value of property list item "Name" of property list items}
set itemCount to itemCount + (count i)
end repeat
if l is not currList then exit repeat
delay 5
end repeat
set currList to l's items
if itemCount is 0 then
set l to l & ("No recent items are currently listed in the plist
file. When you run the script again, " & ¬
"it may take up to a minute (after you have opened another
application or file) to respond.")
else
set l to l & ("All recent items have now been deleted from the plist
file. " & ¬
"For confirmation of this, run the script again immediately.")
end if
set text item delimiters to return & tab
repeat with i from 1 to count typeList
set l's item i to typeList's item i & ({":"} & l's item i)
end repeat
set text item delimiters to return & return
set l to l as Unicode text
set text item delimiters to {""}
beep
activate
display alert "Recent Items" message l
--------
set allreadyRunning to "System Preferences" is in (do shell script
"ps -xwwc")
Incidentally, since process "System Preferences" is targeted by the
script anyway, its existence can be checked directly (thus avoiding
the need for a shell script):
--------
tell application "System Events" to tell process "System Preferences"
set alreadyRunning to exists
tell application "System Preferences" to set current pane to pane
"com.apple.preference.general"
set frontmost to true (* optional *)
tell group 1 of window 1 to repeat with btnNum from 1 to 2
tell pop up button btnNum
set btnVal to value
if btnVal is not "None" then repeat with i in {"None", btnVal}
click
click menu 1's menu item i
repeat until value is i's contents
delay 0.1
end repeat
end repeat
end tell
end repeat
end tell
if not alreadyRunning then quit application "System Preferences"
--------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden