Replace line in .plist file to modify <string> - is it possible?
It's probably easiest to use defaults
to edit it:
defaults write /abs/path/to/plist SomethingElse "randomstuffhere"
Note that you must supply the absolute path to the plist file, and leave the ".plist" off of its filename.
Also (as pointed out in the comments) this tends to convert the plist file to the binary plist format variant; programs that use appropriate .plist reading frameworks will read this fine, but it'll no longer be human-readable. If you want it to be in the XML format variant, you can convert it with plutil -convert xml1 /path/to/plist.plist
.
Alternately, you can use PlistBuddy
instead of defaults
:
/usr/libexec/PlistBuddy -c "Set :SomethingElse 'randomstuffhere'" /path/to/plist.plist
So it's the third line you want to change?
sed -i"" '3{;s\:.*:<string>randomstuffhere</string>:;}' .plist
I think osx sed
supports the -i
option, but you have to tell it to NOT use an backup extension to have it overwrite. Some sed's require that the initial char for the s///, if not a '/', should be esacped, ie \:
. You may only need :
.
I would test this as sed '3{....}' file > newFile
before risking contents of a file. And to test -i""
, work on a copy.
If you're looking to always change the line that has Numbers in it, then use
sed -i"" '\:<string>Numbers.*$:/<string>randomstuffhere</string>:` .plist
IHTH.