Home > front end >  change plist dic/string via osx-terminal
change plist dic/string via osx-terminal

Time:09-21

I'm trying to change two sting keys within a dictionary plist file with the os x onboard tools (via terminal) but I'm having problems. I just switched back to os x after a 10 years break so I'm struggling a bit atm.

plist data

% plutil -p "/Users/username/Library/Preferences/com.Adobe.Common 15.0.plist"                                                          
    {
      "Media Cache" => {
        "DatabasePath" => "/Users/path/somewhere/one"
        "FolderPath" => "/Users/path/somewhere/two"
      }
    }

I tried several command wiht defaults write, plutil & PlistBuddy but I'm not able to change the values to anything else.

% defaults write "/Users/username/Library/Preferences/com.Adobe.Common\ 15.0.plist" "Media Cache" -array-add '{DatabasePath = (test);}'

Could someone help me with this problem? The empty spaces aren't perfect but I have to deal with them...

Best, Ben

CodePudding user response:

You can do it with plutil in 3 steps

  1. Convert to human-readable form:
plutil -convert json -r ~/Library/Preferences/com.Adobe.Common\ 15.0.plist -o ~/my.plist.json
  1. Edit my.plist.json in a text editor.

  2. Convert back to binary plist:

plutil -convert binary1 ~/my.plist.json -o ~/Library/Preferences/com.Adobe.Common\ 15.0.plist

Or, you can try PlistBuddy as described here: https://apple.stackexchange.com/questions/282732/how-do-i-replace-a-value-in-an-plist-array-using-plutil

CodePudding user response:

Using defaults you can change or set your keys this way

defaults write ~/Library/Preferences/com.Adobe.Common\ 15.0.plist "Media Cache" -dict DatabasePath "/Users/path/somewhere/one" FolderPath "/Users/path/somewhere/two"

From man

 -dict       Allows the user to add a dictionary to the defaults database
             for a domain.  Keys and values are specified in order:

                   defaults write somedomain preferenceKey -dict key1 value1 key2 value2
  • Related