I have a script which is passing values to a plist, it's work fine, but I would like to change some of the values without removing everything else.
I used to have a script for that but can't found it at all.
Here is my script which creating the value
tell application "System Events"
set the parent_dictionary to make new property list item with properties {kind:record}
set the plistfile_path to "~/Desktop/MY_DATA.plist"
set this_plistfile to ¬
make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"thename", value:theName}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"creationDate", value:creationDate}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"serialNumber", value:serialNumber}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"Email", value:fullEmail}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"IPAddress", value:IPAddress}
end tell
here is what I wrote for changing the value, but the issue is the plist will only have the new value and all the other properties would be removed
set theName to "demo"
tell application "System Events"
set the parent_dictionary to make new property list item with properties {kind:record}
set the plistfile_path to "~/Desktop/MY_DATA.plist"
set this_plistfile to ¬
make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
make new property list item at end of property list items of contents of this_plistfile ¬
with properties {kind:string, name:"thename", value:theName}
end tell
how can I change some of the value without removing the others ?
Best Answer
Firstly, you can simplify your initial script—the one used to create the property list file—to this:
Then changing a value is as simple as changing an item in the record
plistR
, and settingplistf's value
to the newplistR
:If you don't want the hassle of writing out a whole new record declaration (imagine you had, say, 1000 items and only needed to change one), you can adjust a single plist item also like this: