Saturday, July 4, 2020

#1 2020-04-29 10:54:04 am

LookToWindward
Member
Registered: 2020-04-28
Posts: 14

Property List Suite of System Events

Hi,

I using the property list suite to store persistent data across runs.

I create them initially:

Applescript:

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:

Applescript:

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?

Thanks a lot
Dave

Last edited by LookToWindward (2020-04-29 10:55:02 am)

Offline

 

#2 2020-04-29 11:20:36 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4532

Re: Property List Suite of System Events

Something like :

Applescript:

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

Applescript:

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

Offline

 

#3 2020-04-29 11:29:23 am

LookToWindward
Member
Registered: 2020-04-28
Posts: 14

Re: Property List Suite of System Events

I tried:

Applescript:

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:

Applescript:

   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:"

              Can’t set «class plif» to blah

Any ideas?

Offline

 

#4 2020-04-29 11:37:15 am

LookToWindward
Member
Registered: 2020-04-28
Posts: 14

Re: Property List Suite of System Events

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

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")

--
--  Persistent Properties
--
property pModOrderList : {} as list

Could it be something to do with the  quoted form of ......

Offline

 

#5 2020-04-29 01:01:31 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Property List Suite of System Events

LookToWindward wrote:

Could it be something to do with the  quoted form of ......


I don't think. And why you put everywhere the keyword me? Your script worked for me fine in this form:

Applescript:


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}

Last edited by KniazidisR (2020-04-29 01:18:33 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#6 2020-04-29 01:31:33 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4532

Re: Property List Suite of System Events

LookToWindward wrote:

I tried:

Applescript:

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:

Applescript:

   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:"

              Can’t set «class plif» to blah

Any ideas?




When somebody propose a script, the first thing to do is to exectute exactly what was sent.

You didn't do that.
I ran my two scripts and they worked.
after running thr 1st script, the created file contains :

Applescript:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>pModOrderFileURL</key>
   <string>Barack Obama</string>
   <key>pModOrderList</key>
   <string>President</string>
</dict>
</plist>

after running the 2nd script the file contains :

Applescript:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>pModOrderFileURL</key>
   <string>Soeur Emmanuelle</string>
   <key>pModOrderList</key>
   <string>President</string>
</dict>
</plist>

Isn't it what they were supposed to achieve ?

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'

Applescript:

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     

Applescript:

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)