macosterminalreloaddefaults

Reload com.apple.Terminal.plist


I want use a script to modify the preferences of my terminal for my Mac, so it can close the window when exit the terminal. I use this command in the script:

/usr/libexec/PlistBuddy -c "Set \"Window Settings\":Basic:shellExitAction 0" ~/Library/Preferences/com.apple.Terminal.plist

Now the problem is after execute the script, the .plist file is do changed, I check it by

defaults read com.apple.Terminal "Window Settings"

The value is 0 now.

But the problem is the terminal not reload the .plist file, and when I exit the terminal, it rewrite the .plist file as '2' again. So my question is how to let terminal reload the .plist file when it's running or stop it rewrite the file when it exit.


Solution

  • Sounds like a classic chicken and egg problem to me.

    Terminal writes out its current preferences upon quitting and overwrites any of your changes, yet you need Terminal loaded in order to have a shell to make those changes with PlistBuddy.

    I can think of two solutions here:

    1) write a small script that you can launch from a non-Terminal process... maybe an Applescript or something you can pass into a system call from a tiny Macintosh app? :-)

    2) simply change the "Settings" to what you desire by going to Terminal preferences.