Search code examples
macosshellshplistoh-my-zsh

PlistBuddy - Copying from one plist to another


I am trying to copy the Root Dictionary from a plist file and adding it to another plist file

git clone https://github.com/rahulkatariya/osx-terminal.app-colors-solarized.git

mv osx-terminal.app-colors-solarized/Solarized\ Dark.terminal osx-terminal.app-colors-solarized/Solarized\ Dark.plist

solarizedDark=`/usr/libexec/PlistBuddy -c "Print" osx-terminal.app-colors-solarized/Solarized\ Dark.plist 2>&1`

/usr/libexec/PlistBuddy -c "Add :Window\ Settings:Solarized\ Dark dict $solarizedDark" ~/Library/Preferences/com.apple.Terminal.plist

Error

The output still creates an empty dictionary of Solarized Dark inside Window Settings Dictionary but with 0 items

Terminal Plist Here is the plist i am trying to copy

Solarized Dark Plist


Solution

  • Solved

    I added an empty Dict and then used the Merge command of PlistBuddy to add all entries of the file inside the new dict like below

    /usr/libexec/PlistBuddy -c "Add ':Window Settings:Solarized Dark' dict" ~/Library/Preferences/com.apple.Terminal.plist
    /usr/libexec/PlistBuddy -c "Merge 'osx-terminal.app-colors-solarized/Solarized Dark.plist' ':Window Settings:Solarized Dark'" ~/Library/Preferences/com.apple.Terminal.plist