9

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

2
  • 2
    Can You try absolute path to Your Info.plist file? It works for me (P.S. after this plist is in binary format) Commented Feb 18, 2015 at 18:41
  • That worked! If you add it as a answer I will up-vote and accept it so you get reputation for it.
    – iProgram
    Commented Feb 18, 2015 at 18:45

2 Answers 2

18

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).

7
  • 1
    Thanks, but how can you insert into a deeper level of the plist (say add an item to some internal dictionary)? Here you merely present the key, the type and the value - but no key-path. Commented Feb 16, 2016 at 12:44
  • @MottiShneor I've added example for deeper key path. Commented Feb 16, 2016 at 13:06
  • @MateuszSzlosek is it possible to write entire text using defaults write ? meaning full text to a file to replace content with this new text based content?
    – mjs
    Commented Nov 6, 2019 at 21:57
  • @momomo I'm not sure I fully understand what you mean by that. Please ask new question with more details. Commented Nov 7, 2019 at 8:35
  • @MateuszSzlosek It's ok, i solved it. You can convert a text based xml file into a binary plist file. Using that I can edit the xml as I desire from bash, then save/write all of it, rather than just write small pieces of it.
    – mjs
    Commented Nov 7, 2019 at 13:24
3

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .