views:

33

answers:

1

I am trying to write a script that will add a new key to a dictionary plist. The script works fine when using a string for the key of the dictionary but I can't seem to figure out how to use a variable for the keyname. The script is below and is almost working. THe only issue is being able to use keyName as a variable instead of a string literal (which it is doing now).

on pListAddValueForKey(plistFile, keyName, keyValue)
 tell application "System Events"
      tell property list file plistFile
           tell contents
                set previousValue to value
                set value to (previousValue & {keyName:keyValue}) -- this is the line in need of assistance
           end tell
      end tell
 end tell

end pListAddValueForKey

+1  A: 

Try this...

on pListAddValueForKey(plistFile, keyName, keyValue)
    if class of plistFile is not text then set plistFile to plistFile as text
    tell application "System Events"
        tell property list file plistFile
            tell contents
                make new property list item at end of property list items with properties {name:keyName, value:keyValue}
            end tell
        end tell
    end tell
end pListAddValueForKey
regulus6633
If I could put 2 checks on this answer I would. AppleScripting plists has been killing me. Thanks!
uprise
Glad I could help uprise!
regulus6633