Basically I want to know if it's possible to create a script to edit an entry in a .plist file. However I don't want to replace a specific string, but the entire line so a new string can be added as the property will keep changing. An example:
<string>Something</string>
<key>SomethingElse</key>
<string>Numbers</string>
<key>Entry</key>
And having the third line changed to something like the following, regardless of what that line currently says.
<string>randomstuffhere</string>
I've been looking for a couple of hours and I think it's probably possible using sed but after looking at examples I can't seem to decipher it to construct it myself. Any and all help is appreciated. Oh, and I'd like to avoid using perl if possible.
EDIT: When using the following, the changes are made in the Terminal window but it doesn't seem to save it to the file. Using -i is apparently the way to fix this but it throws an error for me, so I'm not sure what I'm doing wrong.
sed -n '/SomethingElse/{p;n;s/>.*</>randomstuffhere</;};p' my.plist
All you have to do is click on the blue project icon -on top of the left- and go to the “Build Settings” tab, search “Info. plist” and choose “Info. plist File” section. Then change the information of the section from your folder's name.
plist file. If you need to edit these items, Control-click (or right-click) Info. plist in the sidebar and select Edit Manually. This allows you to add or edit items in raw XML format.
Syntax of plist is pretty much like XML, so you can use XML style comments. By the way, you can select a portion of plist text and press cmd-/ (like you do for making a single-line comment in regular . m, . h files) and XCode will comment selected block for you automatically.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With