"Property List File" question

Working with the excellent script posted by Kai to modify the plist file “com.apple.screensaver.xxxxxxx” in the “ByHost” folder of Preferences, I ran into a construct that I can’t figure out.

if I use this code, as written by Kai:


set prefsFolder to (path to "pref")'s POSIX path & "ByHost/"
tell application "System Events"
	set prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.apple.screensaver.")'s POSIX path)
	tell prefsFile
		set value of property list item "moduleName" to "Computer Name"
		set value of property list item "idleTIme" to 180
		set value of property list item "modulePath" to "/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/Computer Name.saver"
	end tell
end tell

Everything works fine. Notice the “'s POSIX path” in the first line of the System Events tell block. If I remove this clause, as in:


set prefsFolder to (path to "pref")'s POSIX path & "ByHost/"
tell application "System Events"
	set prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.apple.screensaver."))
	tell prefsFile
		set value of property list item "moduleName" to "Computer Name"
		set value of property list item "idleTIme" to 180
		set value of property list item "modulePath" to "/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/Computer Name.saver"
	end tell
end tell

Then the scriptlet still compiles, but gets a runtime error

What is it about adding the “'s POSIX path” (equivalent to “POSIX path of”) that makes it able to be made into a “reference” (what kind of reference???) whereas the “file xxx:yyy:zzz.plist” apparently can’t be made into a reference?

Kai, are you there bud?

TIA

Johnny

Edit: Nevermind me, see Nigel’s post below.

The Property List Suite can take either either a POSIX path or an HFS path after the keyword property list file. The problem is that the expression (folder prefsFolder’s first file where name starts with “com.apple.screensaver.”) returns a System Events reference to the file, not a path. kai’s POSIX path coercion produces a path, Johnny’s lack of one doesn’t, so his overall line is a bad property list file specifier.

It doesn’t seem that System Events references can be coerced directly to HFS paths like Finder references can, but, if necessary, they can be coerced to alias and thence to HFS path:

tell application "System Events"
	display dialog ((folder prefsFolder's first file where name starts with "com.apple.screensaver.") as alias as Unicode text)

	set prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.apple.screensaver.") as alias as Unicode text)
end tell

I have a dream … that one day, little Finder file references and little alias file references and little POSIX file references and little System Events file references and little Path To references and little ‘file xxx’ references and little ‘folder xxx’ references will all be able to join hands and play in harmony… and that if a string is a valid path then AS will recognize it and use it as a path, and if it is a valid alias then AS will recognize that and use it as an alias, and if it is a valid POSIX path then by Golly it will recognize that too and let you use it as a file reference. I have a dream today.

Seriously, I’ve been doing this practically daily since AS first came out and I still have to jack around for about 30 minutes every time I want to refer to a file or a folder, trying to find the magic construct that works. Some need a Finder wrapper, some don’t. This file specification thing has to be the biggest stumbling block to just getting a new script written and working, at least for me. I NEVER get it right on the first 75 tries.

So there is a “System Events” file reference class?

Hi

Just implemented this script but have a question.

How do you add a new property list item? Changing the value of an existing one works but I need to add a new property list item and give it a value. Any hints?

Thanks

Hi

Have worked out how to add a property list item but now stuck on how to delete a property list item.

I have the following:


set prefsFolder to (path to "pref")'s POSIX path
tell application "System Events"
	set prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.irislink.mac.Drop2Read.plist")'s POSIX path)
	tell prefsFile
		delete property list item "Target"
	end tell
end tell

Which gives this error:

Can anyone help?

Thanks

Oh… now I can use this instead of “do shell script.” Woot!

Hi, Andrew.

I haven’t tried deleting anything from my own property list files (!) but your error message looks like a scope problem. Have you tried telling System Events directly (rather than the property list file) to do the deletion?


set prefsFolder to (path to "pref")'s POSIX path
tell application "System Events"
	set prefsFile to property list file ((folder prefsFolder's first file where name starts with "com.irislink.mac.Drop2Read.plist")'s POSIX path)
	delete property list item "Target" of prefsFile
end tell

Thanks for the replies. I tried Nigel’s script but got the same error message, I am afraid. So still unable to delete property list items…