Hi Folks,
I have Googled & found a few threads associated with using Applescript to inspect plist file entries, but no matter what I try, I can’t quite get the syntax right for making an update, or maybe I am missing something. The article at http://www.mactech.com/articles/mactech/Vol.22/22.03/StoringandAccessingData/index.html was a good start, & goes some way to explaining how database support & plist files are supported.
Some programs set the “NSRecentDocumentRecords” array (as inspected by the Plist Editor PLE) and I would like to delete some entries from this so the recent list avoids overflowing with temporary junk or whatever, keeping files I am more interested in. I understand Applescript now knows about plist files and can update records in them - somehow. Below is the main bit of my simple first attempt to only keep the first 2 items in the list. It fails to update the plist file correctly, even though it looks like it tries to…
tell application "System Events"
-- get the current list from the plist file
set recent to get (value of property list item "NSRecentDocumentRecords" of contents of property list file listfile)
-- return count value of recent
-- get |_NSAlias| of |_NSLocator| of item 2 of recent
-- Make a new empty list and then add desired entries to it
set newlist to {}
set newlist to newlist & {item 1 of recent}
set newlist to newlist & {item 2 of recent}
-- replace the old plist file record with the new one
set value of property list item "NSRecentDocumentRecords" of contents of property list file listfile to newlist
-- check if it worked OK
get (value of property list item "NSRecentDocumentRecords" of contents of property list file listfile)
return count of newlist
The event log (truncated in places of long data) for this looks like:-
get value of property list item "NSRecentDocumentRecords" of contents of property list file "/Users/f/Library/Preferences/org.videolan.vlc.plist"
{{|_NSLocator|:{|_NSAlias|:«data
****0000000001E400020000094D616320484420503100000000000000000000000482B00000024A63B1F6E02000FFFFF0000»}}, {|_NSLocator|:{|_NSAlias|:«data ****00000000018A00020000094D61632048442050310000000000000000000000000000E00012F0000150002000FFFFF0000»}}, {|_NSLocator|:{|_NSAlias|:«data
****00000000014C00020000094D6163204844205031000000000000000000000002F661300012F0000150002000FFFFF0000»}}}
set value of property list item "NSRecentDocumentRecords" of contents of property list file "/Users/f/Library/Preferences/org.videolan.vlc.plist" to {{|_NSLocator|:{|_NSAlias|:«data
****0000000001E400020000094D61632048442050310000000000000000000000000482B00000024A63B1F6E02000FFFFF0000»}}, {|_NSLocator|:{|_NSAlias|:«data
****00000000018A00020000094D61632048442050310000000000000000000000000482B0000001533AF1443732E0020FF0000»}}}
get value of property list item "NSRecentDocumentRecords" of contents of property list file "/Users/f/Library/Preferences/org.videolan.vlc.plist"
{{|_NSLocator|:{}}, {|_NSLocator|:{}}}
The get shows 3 entries are read
The set shows 2 entries are written AND the parameters look correct
The next get shows 2 empty records - what happened to the data?
Does the applescript syntax for plist files only work when in the nested tell block format?
It is like I am not building my newlist correctly, but the event log looks OK where it is written by the set command…
Many thanks for any help
Cheers
Michael
Model: MacBook Pro 17" Intel
Browser: Safari 533.19.4
Operating System: Mac OS X (10.5)