Remove element from a plist file?

Hi All,

I’m trying to write a script that will remove an element from a plist file. The plist files in question contain settings for RAW image files and I want to delete a key called “ProcessedList”, which is an array, from the plist file.

I’ve tried


do shell script "defaults delete /Volumes/Work Temp HD/0703-15 Dayspring/Captures/Capture One Settings/ImageSettings/50488_Styled.TIF ProcessedList"

--AND

do shell script "defaults delete /Volumes/Work Temp HD/0703-15 Dayspring/Captures/Capture One Settings/ImageSettings/50488_Styled.TIF.plist ProcessedList"

and the property list suite


tell application "System Events"
	tell property list file "/Volumes/Work Temp HD/0703-15 Dayspring/Captures/Capture One Settings/ImageSettings/50488_Styled.TIF.plist"
		tell contents
			delete property list item "ProcessedList"
		end tell
	end tell
end tell

I can set the value like this


tell application "System Events"
	tell property list file "/Volumes/Work Temp HD/0703-15 Dayspring/Captures/Capture One Settings/ImageSettings/50488_Styled.TIF.plist"
		tell contents
			set value of property list item "ProcessedList" to "70"
		end tell
	end tell
end tell

With the property list suite I get the error “System Events got an error: NSReceiversCantHandleCommandScriptError” I don’t have any trouble adding or removing values of property list items but can’t seem to remove an element.

Any Ideas? Seems odd to me that the suite let’s you read and write and create new elements but not delete them.

Thanks In Advance,
MT

I’m not sure that this will do what you want, but you might want to take a look at:

http://www.latenightsw.com/freeware/PListTools/index.html

I used to have this installed, but I never really used it. I recently deleted all non-Apple scripting additions because I was getting spurious output from calling “system info”. I’m not sure if this scripting addition was the culprit, because I deleted a bunch of them since I really didn’t use them very much. If you run “system info” and get a very long output with a number of error reports, then maybe this was the culprit (although I had a few much older scripting additions than this one, and Mark Alldritt keeps his stuff up to date and working well…).

hth

Vince

Hi Vince,

I’ve looked at that but not tried it yet. I was hoping to stay away from any additions so it will be more portable. Thanks for the suggestion though.

Mark

After some further testing I deciphered that I wasn’t using the quoted form of the path to the file so the error was due to a space in path. Now I have it working.


--remove the extension ".plist"
set myPath to "\"/Users/marktorrance/Pictures/Capture One Default Session/Captures/Capture One Settings/ImageSettings/Al_0009.TIF\"" as string

do shell script "defaults delete " & myPath & " ProcessedList"

or


set myPath to "/Users/marktorrance/Pictures/Capture One Default Session/Captures/Capture One Settings/ImageSettings/Al_0009.TIF" as string

do shell script "defaults delete " & (quoted form of POSIX path of myPath) & " ProcessedList"

Thanks Anyway,
Mark

Hi Mark,

a little note:
myPath is a string and is a POSIX path


set myPath to "/Users/marktorrance/Pictures/Capture One Default Session/Captures/Capture One Settings/ImageSettings/Al_0009.TIF"
do shell script "defaults delete " & (quoted form of myPath) & " ProcessedList"

You need the POSIX path coercion only if you have a HFS path like


set myPath to ((path to pictures folder as Unicode text) & "Capture One Default Session:Captures:Capture One Settings:ImageSettings:Al_0009.TIF")
do shell script "defaults delete " & (quoted form of POSIX path of myPath) & " ProcessedList"

Hey StefanK,

Thanks for pointing out the unnecessary coercion. The whole path coercion thing is much clearer to me now. All I was lacking in my original approach was using “quoted form of” to avoid the spaces in the path being a problem. Is there anyway to delete a key using the Property List Suite of System Events? Just curious if I have other options of achieving this.

Thanks Again,
Mark