I’ve got a couple of scripts that check data for recent Pages '09 app documents that are now broken in El Capitan (MacOSX10.11.6) +
The scripts check the “com.apple.iWork.Pages.LSSharedFileList.plist” file in ~/Library/Preferences. But this is now an empty file ??? Pages still updates recent docs in the menu, so it’s getting the data from somewhere !!! I’ve tried looking in ~/Library/Containers… there’s no “com.apple.iWork” folder as expected.
It’s the same for other scripts that employ similar strategies for other apps like Preview etc. I get an error when it tries to read the associated LSSharedFileList file. It worked fine in Yosemite/Mavericks, so maybe there’s a change in the system.
Any ideas where the data for recent docs for apps is now stored?
One of the scripts below. Suggestions please!
--"clear recent docs" v7 by Alnoor Feb 2014 for Mavericks
--Selectively clear listed documents in Pages "Open Recent" Menu & trash "version" files
--NB: Clears ALL recent menu items in Finder!!
-----------------------
--PROPERTIES:
global prefsFile
property token : ASCII character 165 -- "¢"
property prefsName : "com.apple.iWork.Pages.LSSharedFileList"
property defaultPrefsRecord : {|RecentDocuments|:{|Controller|:"CustomListItems", |CustomListItems|:{}, |MaxAmount|:10}}
set path2prefs to (path to preferences)
set prefsFolder to path2prefs as alias
--HANDLERS:
--SEARCHANDREPLACE
on searchAndReplace(txt, srch, rpl)
set AppleScript's text item delimiters to {srch}
set temp to every text item of txt
set AppleScript's text item delimiters to {rpl}
set temp to (temp as string)
set AppleScript's text item delimiters to {""}
return temp
end searchAndReplace
--REWRITE PLIST
on rewriteplist(myRecord)
tell application "System Events"
prefsFile as text
set value of property list file the result to myRecord
end tell
end rewriteplist
--MENU CLICK
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
--...
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
--SCRIPT:
--welcome
activate
display dialog "Remove selected documents from \"Open Recent\" Menu?" with icon 1
--initialize
set iquitpages to false
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
set iquitpages to true
delay 2
end if
tell application "Finder"
set prefsFile to (file (prefsName & ".plist") of prefsFolder) as alias --keep in line with other apps!!
end tell
--read pList
tell application "System Events"
tell property list file (prefsFile as text)
if (it exists) then
tell property list item "RecentDocuments"
tell property list item "CustomListItems"
-- Get a list of the menu item names and a parallel list of plists for the associated data.
set {RecentNames, RecentBookmarks, RecentPlists} to {value of property list item "Name", value of property list item "Bookmark", text} of every property list item --<data> of (Bookmarks & Icon) cannot be read into a record, they must be read explicitly as <text>
--check for uniqueness...
--add token(s) to duplicate names only
repeat with i from 2 to (count RecentNames) --i.e skip first, and compare with proceeding items only
repeat with j from 1 to i
if i is not j then --skip self
if (item i of RecentNames) is (item j of RecentNames) then
set (item i of RecentNames) to (item i of RecentNames) & token
end if
end if
end repeat
end repeat
end tell
end tell
else
--error --No pList!!
activate
display dialog "No recent documents for \"Pages\" found!" buttons {"Cancel"} default button 1 with icon 0
end if
end tell
end tell
--select the names of the items to remove from the menu.
activate
try
set namesToCut to (choose from list RecentNames with prompt "Delete document(s):" OK button name "Delete" with multiple selections allowed)
on error
--no recent items!!
display dialog "No recent documents for \"Pages\" found!" buttons {"Cancel"} default button 1 with icon 0
end try
if (namesToCut is false) then
error number -128 --User cancelled
else
--trash version files?
set trashversionfiles to false
display dialog "Trash version file(s) too?" buttons {"No", "Yes"} default button 2 with icon 1
set button_returned to button returned of the result
if button_returned is "Yes" then
--Yes
set trashversionfiles to true
--get recent file paths
if (RecentBookmarks is not {}) then
set accessRef to (open for access file ((path to temporary items as text) & "Bookmark.dat") with write permission)
repeat with i from 1 to (count RecentBookmarks)
try
set eof accessRef to 0
write item i of RecentBookmarks to accessRef
set item i of RecentBookmarks to (read accessRef from 1 as «class bmrk») --aliases!!
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1 with icon 0
end try
end repeat
close access accessRef
end if
end if
--delete from plist
my rewriteplist(defaultPrefsRecord) --replace plist with empty default, because "set value to {}" is FAILING in mavericks!!***
tell application "System Events"
tell property list file (prefsFile as text)
tell property list item "RecentDocuments"
tell property list item "CustomListItems"
-- Recreate the items to keep from their plist texts.
repeat with i from 1 to (count RecentNames)
try
if (item i of RecentNames is not in namesToCut) then
make new property list item at end of property list items with properties {text:item i of RecentPlists}
else
if trashversionfiles is true then
--trash version file
set thisitem_version to (item i of RecentBookmarks) as text
set thisitem_version to my searchAndReplace(thisitem_version, ".pages", "~.pages")
tell application "Finder"
if exists alias thisitem_version then
delete alias thisitem_version
end if
end tell
end if
end if
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1 with icon 0
end try
end repeat
end tell
end tell
end tell
end tell
--clear Finder recent items menu
my menu_click({"Finder", "Apple", "Recent Items", "Clear Menu"})
--done
if iquitpages is true then
set btn1 to "Done"
set btn2 to "Open Pages"
else
set btn1 to "Open Pages"
set btn2 to "Done"
end if
display dialog "Selected document(s) removed." buttons {btn1, btn2} default button 2 with icon 1
set button_returned3 to button returned of the result
--open Pages
if button_returned3 is "Open Pages" then
tell application "Pages" to activate
end if
end if
--END