I am writing an applescript to selectively remove the documents listed in Pages “Open Recent” Menu by modifying the pList. (Pages only gives you the option to clear all.)
The applescript is failing to write back “data” type values to the pList…
e.g. Item 0 of CustomListItems of RecentDocuments of the pList “com.apple.iWork.Pages.LSSharedFileList.pList” should contain 3 values:
Bookmark (of type Data)
Icon (of type Data)
Name (of type String)
My applescript only writes the Name value, even though as far as I can tell it contain all the correct data.
Any ideas?
WARNING: Before you run this script, be sure to back up your pList!!
--"edit recent documents" v1 by Alnoor
--Selectively remove listed documents in Pages "Open Recent" Menu
-----------------------
--PROPERTIES:
global prefsFile
(*
global myData
*)
property prefsFolder : (((path to home folder) as text) & "Library:Preferences:") as alias
property prefsName : "com.apple.iWork.Pages.LSSharedFileList"
--HANDLERS:
--VERIFY PLIST
on verifyplist()
tell application "Finder"
if not (exists file (prefsName & ".plist") of folder prefsFolder) then
display dialog "No recent documents for \"Pages\" found!" buttons {"Cancel"} default button 1 with icon 0
else
set prefsFile to (file (prefsName & ".plist") of prefsFolder) as alias
end if
end tell
end verifyplist
--READ SINGLE KEY
on readsinglekey(myKey)
tell application "System Events"
prefsFile as text
value of property list item myKey of property list file the result
end tell
end readsinglekey
--WRITE SINGLE KEY
on writesinglekey(myKey, myValue)
tell application "System Events"
prefsFile as text
set (value of property list item myKey of property list file the result) to myValue
end tell
end writesinglekey
--QUIT PAGES
on quitPages()
tell application "System Events" to get name of processes
set application_list to result
if application_list contains "Pages" is true then
display dialog "\"Pages\" will quit!" buttons {"Cancel", "Continue"} default button 2 with icon 0
tell application "Pages" to quit
end if
end quitPages
--SCRIPT:
--welcome
display dialog "Remove selected documents from \"Open Recent\" Menu?" with icon 1
--initialize
my quitPages()
my verifyplist()
set myData to my readsinglekey("RecentDocuments") --i.e "RecentDocuments" of pList
set myCustomListitems to CustomListItems of myData --i.e "CustomListItems" of pList
--read Names of Recent Docs...
set myNames to {}
repeat with i from 1 to count of myCustomListitems
set aName to |Name| of item i of myCustomListitems
set myNames to myNames & aName
end repeat
--choose recent docs to delete
activate me
set mySelection to choose from list myNames with prompt "Delete document(s):" with multiple selections allowed
if mySelection is not false then --i.e user didn't cancel
--make new CustomListitems
set myCustomListitems_new to {}
repeat with i from 1 to count of myCustomListitems
set aName to |Name| of item i of myCustomListitems
if aName is not in mySelection then
set myCustomListitems_new to myCustomListitems_new & {item i of myCustomListitems}
end if
end repeat
--make new data
set myData_new to myData
set CustomListItems of myData_new to myCustomListitems_new
--write to pList
my writesinglekey("RecentDocuments", myData_new) --*******PROBLEM HERE: ONLY writing "Name" entries of CustomListItems (even though myData_new contains data for "Bookmark" & "Icon")???********
end if
--END
AppleScript: 2.3
Browser: Safari 534.57.2
Operating System: Mac OS X (10.6)