terminalbooleandefaults

Use Shell Script to write to plist Dictionary child Boolean


I'm trying to modify a system plist in an Platypus script-based app (Mac), though I have a feeling my question may have a more general answer.

The question is: What is the correct Terminal syntax for targeting and modifying the boolean child of a Dictionary key in a plist file?

I tried:

sudo defaults write /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist com.github.norio-nomura.SIMBL-Agent Disabled -bool false

but it doesn't like -bool with Disabled there..


Solution

  • I managed to solve it by using PlistBuddy instead. PlistBuddy is built into MacOS X 10.5 and above.

    I could have used:

    /usr/libexec/PlistBuddy -c "set :com.github.norio-nomura.SIMBL-Agent:Disabled bool" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
    

    But it caused an error in the .pkg installer, so I used:

    /usr/libexec/PlistBuddy -c "Delete :com.github.norio-nomura.SIMBL-Agent" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
    

    .. and then:

    /usr/libexec/PlistBuddy -c "Add :com.github.norio-nomura.SIMBL-Agent:Disabled bool" /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist
    

    .. right after that which appears to be working.