Changing Info.plist values via terminal

I am making my own application and I would like to change some values in my Info.plist file using terminal.

I have tried doing defaults write Info.plist CFBundleExecutable -string <Executable> and defaults write Info.plist CFBundleExecutable <Executable> however it never seems to work. I don't get any output so I don't even know what it is i'm doing wrong.

Thanks for the help


Solution 1:

You can use defaults or plutil command line tools.

For defaults it looks like this:

defaults write /absolute/path/to/Info.plist CFBundleExecutable -string <Executable>

For plutil:

plutil -insert CFBundleExecutable -string <Executable> Info.plist 

Value after -insert is a key path separated by .. For example

plutil -insert CFBundleDocumentTypes.0.CFBundleTypeExtensions.1 -string "scss" /Applications/Safari.app/Contents/Info.plist

will insert "scss" string deep in the path. Numbers after . are for arrays (they are starting with 0).

Solution 2:

GET Value - supply raw key

/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" Info.plist

SET Value - supply raw key and value

/usr/libexec/PlistBuddy -c "Set CFBundleExecutable <Executable>" Info.plist