System Events - Property Lists


Shane Stanley
 

On 1 May 2020, at 8:07 pm, Dave <dave@looktowindward.com> wrote:

It’s hard to know when you need (), I usually add them anyway but this time I forgot!
If you'd used "my" instead of "of me" the compiler would have inserted them for you.

--
Shane Stanley <sstanley@myriad-com.com.au>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Dave
 

Hi,

It’s hard to know when you need (), I usually add them anyway but this time I forgot!

The thing that threw me here was again the error message, it actually display the correct path name in the error which I took to mean the parameter itself was ok.

I’ve found System Events adequate for that I want, which is pretty simple.

All the Best
Dave

On 1 May 2020, at 05:10, Shane Stanley <sstanley@myriad-com.com.au> wrote:

On 1 May 2020, at 6:02 am, Dave <dave@looktowindward.com> wrote:

That used to read:

tell property list file pMWLPrefsFilePOSIXPath of me

So, assigning it to local storage and using the local made it work! wtf! AppleScript is in a class of its own when it comes to weird happens!!!
No, what fixed it was that you stopped misusing "of me".

Your original is looking for a property list file "of me", where only the variable belongs to "me".

If you had said:

tell property list file (pMWLPrefsFilePOSIXPath of me)

it would work fine.

But you'll find it's much simpler and faster to use AppleScriptObjC for property lists. System Events is pretty poor at it.


--
Shane Stanley <sstanley@myriad-com.com.au>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>




Shane Stanley
 

On 1 May 2020, at 6:02 am, Dave <dave@looktowindward.com> wrote:

That used to read:

tell property list file pMWLPrefsFilePOSIXPath of me

So, assigning it to local storage and using the local made it work! wtf! AppleScript is in a class of its own when it comes to weird happens!!!
No, what fixed it was that you stopped misusing "of me".

Your original is looking for a property list file "of me", where only the variable belongs to "me".

If you had said:

tell property list file (pMWLPrefsFilePOSIXPath of me)

it would work fine.

But you'll find it's much simpler and faster to use AppleScriptObjC for property lists. System Events is pretty poor at it.


--
Shane Stanley <sstanley@myriad-com.com.au>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


Dave
 

If I change it to:

tell application "System Events"
set myPropertyListPath to pMWLPrefsFilePOSIXPath of me ———Changed------
tell property list file myPropertyListPath ———Changed------
set pModOrderFileURL of me to (value of property list item "pModOrderFileURL")
set pModOrderList of me to value of property list item "pModOrderList"
set pGameInfoList of me to value of property list item "pGameInfoList"
set pModInfoList of me to value of property list item "pModInfoList"
end tell
end tell

That used to read:

tell property list file pMWLPrefsFilePOSIXPath of me

So, assigning it to local storage and using the local made it work! wtf! AppleScript is in a class of its own when it comes to weird happens!!!


Dave
 

Ok, I now think it IS because I don’t have a Property List File Object,

Creation:

set myParentDictionary to make new property list item with properties {kind:record}

— File Object in 
set myPropertyListFile to make new property list file with properties {contents:myParentDictionary, name:pMWLPrefsFilePOSIXPath of me}

tell application "System Events"
tell property list file pPrefsFileObject of me
set pModOrderFileURL of me to value of property list item "pModOrderFileURL"
set pModOrderList of me to value of property list item "pModOrderList"
set pModInfoList of me to value of property list item "pModInfoList"
end tell
end tell

—Test Reading Back here, works ok
tell property list file myPropertyListFile of me
set pModOrderFileURL of me to (value of property list item "pModOrderFileURL")
set pModOrderList of me to value of property list item "pModOrderList"
set pModInfoList of me to value of property list item "pModInfoList"
end tell


It does this if it doesn’t find a prefs file, to create one.

Then of subsequent Run of the Script I want to restore them:

—  This doesn’t work since I’m passing the File Path String instead of a File Object
--
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"
set pModInfoList of me to value of property list item "pModInfoList"
end tell
end tell

But I don’t have the File Object that was around (myPropertyListFile) when it was created. So, given the file on the disk, how to I get a new a File Object? 

I am assuming you can read back the file?!?!? It doesn’t actually say you can, it would be typical of Apple to give you something to write a property list but not give you one to read it back again, and when it comes to AppleScript it wouldn’t surprise me in the least.

Fed up with poor documentation…..

All the Best
Dave


















Dave
 

Hi, 

it doesn’t look if it is:

=I’m guessing its because it expects a Property List File Object, not a Path String, however I’m at a loss as to know how to get this object, when it was created I was making a new file, but now I want to reference the same file, bet I can’t find a way of objecting the Object for an existing plist file.

Since it accepts a property list. I can write it ok and look at the file in XCode, however when I come to read back the values it gives error:

value of property list item "pModOrderFileURL" of property list file "/Users/surfacedetail/Documents/MWL/MWLPrefs/MWLPrefs.plist”

Its like it doesn’t release that “value” is a property of the Object. This is confusing, should it be a Property File Object or a File Path? Or can it be either. I can’t find any documentation on this and hardly any examples. The one decent example I found does it this way.

I’ve been stuck on this for over 2 hours and can’t fathom what it needs to make it happy! I really loath this aspect of apple script poor docs, unhelpful error message and no support (except places like this).

Oh well, could be worse I suppose.

Thanks in advance for any suggestions.

All the Best
Dave


Dave
 

Hi All,

I have a question about the System Events Property List Suite.

I have code to setup a property list file and it seems to work ok.

It creates it and sets it to the initial values:

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 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}
make new property list item at end with properties {kind:list, name:"pModInfoList", value:pModInfoList of me}
end tell

To update values to:

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

This all work ok (or seems to), however when I come to restore the values:

tell application "System Events"
tell property list file pPrefsFileObject of me
set pModOrderFileURL of me to value of property list item "pModOrderFileURL"
set pModOrderList of me to value of property list item "pModOrderList"
set pModInfoList of me to value of property list item "pModInfoList"
end tell
end tell

I get an error:

value of property list item "pModOrderFileURL" of property list file "/Users/surfacedetail/Documents/MWL/MWLPrefs/MWLPrefs.plist”.

I’m guessing its because it expects a Property List File Object, not a Path String, however I’m at a loss as to know how to get this object, when it was created I was making a new file, but now I want to reference the same file, bet I can’t find a way of objecting the Object for an existing plist file.

Any help greatly appreciated.

All the Best
Dave