On Feb 11, 2010, at 1:56 AM, SHIVANK AGGARWAL, Noida wrote: Please let me know how I can access the values from a plist using Applescript Like I have a attribute ownerid = “Shivank” in plist how can I access that value using applescript.
The basic technique is to read & write the entire plist file. Like this ...
-- prefsFile is an alias to a preference file (or any .plist file) tell application "System Events" set prefsRec to (value of property list file ((prefsFile as text))) --<<<<<< READ end tell
-- prefsRec is an AppleScript record. Modify this record as desired.
tell application "System Events" set value of property list file (prefsFile as text) to prefsRec -- <<<<<<< WRITE end tell
If the .plist file is large, you may want to read & write only a single key in the file. Like this ...
-- prefsFile is an alias to a preference file (or any .plist file) -- "someKey" is the name of an item of the plist file at the root level. tell application "System Events" set myKeyValue to (value of property list item "someKey" of property list file (prefsFile as text)) end tell
-- the class of myKeyValue is the class of the key as shown in the .plist file -- array = list, Dictionary = record, the others are obvious -- modify myKeyValue as desired, then
tell application "System Events" set (value of property list item "someKey" of property list file (prefsFile as text)) to myKeyValue end tell
Writing the .plist file is necessary only if you need to save the modified value.
|