I using the property list suite to store persistent data across runs.
I create them initially:
set myParentDictionary to make new property list item with properties {kind:record}
--
-- Create a new property list file using the empty dictionary list item as contents
--
set myPropertyListFile to make new property list file with properties {contents:myParentDictionary, name:pMWLPrefsFilePOSIXPath of me}
tell property list items of myPropertyListFile
make new property list item at end with properties {kind:string, name:"pModOrderFileURL", value:pModOrderFileURL of me}
make new property list item at end with properties {kind:list, name:"pModOrderList", value:pModOrderList of me}
end tell
and restore them like this:
tell application "System Events"
tell property list file pMWLPrefsFilePOSIXPath of me
set pModOrderFileURL of me to value of property list item "pModOrderFileURL"
set pModOrderList of me to value of property list item "pModOrderList"
end tell
end tell
But I can’t for the life of me work out how to update them? Do I have to write out a new plist file each time or what?
set p2d to path to desktop as string
set pPath to POSIX path of (p2d & "myProps.plist")
tell application "System Events"
set myParentDictionary to make new property list item with properties {kind:record}
set myPropertyListFile to make new property list file with properties {contents:myParentDictionary, name:pPath}
tell property list items of myPropertyListFile
make new property list item at end with properties {kind:string, name:"pModOrderFileURL", value:"Barack Obama"}
make new property list item at end with properties {kind:list, name:"pModOrderList", value:"President"}
end tell
end tell
set p2d to path to desktop as string
set pPath to POSIX path of (p2d & "myProps.plist")
tell application "System Events"
tell property list file pPath
set value of property list item "pModOrderFileURL" to "Soeur Emmanuelle"
end tell
end tell
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 29 avril 2020 19:20:29
on SetPersistentValue(thePropertyName, theValue)
tell application "System Events"
tell property list file pMWLPrefsFilePOSIXPath of me
set value of property list item thePropertyName to theValue
end tell
end tell
end SetPersistentValue
and its called like so:
set myModOrderList to GetModOrderList()
set pModOrderList of me to myModOrderList
get SetPersistentValue("pModOrderList", pModOrderList of me)
I get an error of the “set value of property list item” statement:"
I’ve disabled the SetPersistentValue handler, and when I do a second run, it fails to restore the properties, I get an error:
Can’t get value of property list item "pModOrderFileURL" of property list file "/Users/surfacedetail/Documents/MWLPrefs/MWLPrefs.plist"." number -1728 from «class valL» of «class plii» “pModOrderFileURL” of «class plif» “/Users/surfacedetail/Documents/MWLPrefs/MWLPrefs.plist”
The properties as defined as:
property pMWLPrefsFilePOSIXPath : (pMWLPrefsFolderPOSIXPath of me) & pMWLPrefsFileName of me
I don’t think. And why you put everywhere the keyword me? Your script worked for me fine in this form:
property pMWLPrefsFilePOSIXPath : ((path to desktop) as text) & "TestPlistFile.plist"
property pModOrderFileURL : quoted form of "https://raw.githubusercontent.com/subtledoctor/OS-X-Weidu-Launcher/master/Mac_Weidu_Launcher_v7.app/Contents/Resources/mod_order.txt"
property pModOrderList : {}
tell application "System Events"
-- create plist file
set myParentDictionary to make new property list item with properties {kind:record}
set myPropertyListFile to make new property list file with properties {contents:myParentDictionary, name:pMWLPrefsFilePOSIXPath}
tell property list items of myPropertyListFile
make new property list item at end with properties {kind:string, name:"pModOrderFileURL", value:pModOrderFileURL}
make new property list item at end with properties {kind:list, name:"pModOrderList", value:pModOrderList}
end tell
-- retrieve plist file key's values
tell property list file pMWLPrefsFilePOSIXPath
set pModOrderFileURL to value of property list item "pModOrderFileURL"
set pModOrderList to value of property list item "pModOrderList"
end tell
-- change plist file key's values (update)
tell property list file pMWLPrefsFilePOSIXPath
set value of property list item "pModOrderFileURL" to "Barac Obama"
set value of property list item "pModOrderList" to {"President"}
set pModOrderFileURL to value of property list item "pModOrderFileURL"
set pModOrderList to value of property list item "pModOrderList"
end tell
end tell
return {pModOrderFileURL, pModOrderList}
As I’m not a sooth sayer, at this time I don’t know where is pMWLPrefsFilePOSIXPath defined and don’t know why you use ‘of me’
on SetPersistentValue(thePropertyName, theValue)
tell application "System Events"
tell property list file pMWLPrefsFilePOSIXPath -- of me
set value of property list item thePropertyName to theValue
end tell
end tell
end SetPersistentValue
Always at this time I don’t know I don’t know what is returned by : GetModOrderList() and why you are using ‘of me’ in the 2nd script when it seems that
set myModOrderList to GetModOrderList()
set pModOrderList to myModOrderList
SetPersistentValue("pModOrderList", pModOrderList )
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 29 avril 2020 21:26:12