Reload com.apple.Terminal.plist

I want to use a script to change my terminal settings for my Mac, so it can close the window when exiting the terminal. I use this command in a script:

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

Now the problem is that after the script is executed, the .plist file will be changed, I will check it for

defaults read com.apple.Terminal "Window Settings"

Now the value is 0.

But the problem is that the terminal does not reload the .plist file, and when I exit the terminal, it again overwrites the .plist file as "2". So my question is how to let the terminal reload the .plist file at startup or stop it from rewriting the file when it exits.

+6
source share
4 answers

Sounds like a classic chicken and egg problem.

The terminal writes out its current settings on exit and overwrites any changes you make, but you need a terminal to have a shell for making these changes using PlistBuddy.

I can think of two solutions here:

1) write a small script that you can run from a non-terminal process ... maybe Applescript or something that you can pass to the system call from a tiny Macintosh application ?:-)

2) just change the "Settings" to what you want by going to the terminal settings.

+2
source

In 10.9 (Mavericks) preferences are cached. After overwriting your settings from the terminal, you need to read them using

 defaults read com.apple.Terminal 

and then close and restart the terminal.

I have my terminal settings on my server, so the full command that I use on a new computer or in a new profile is:

 curl -o ~/Library/Preferences/com.apple.Terminal.plist http://example.com/xyz/com.apple.Terminal.plist.`sw_vers \ | grep 'ProductVersion:' \ | grep -o '10\.[0-9]*'` \ && defaults read com.apple.Terminal 
+10
source

My adapted solution works on OS X Mavericks (too).

In the example, I add a new PermanentServer to connect ssh to Terminal -p 22 www.example.com -l user -L 33306:localhost:3306

  • Close the terminal application
  • Open the plist file in Xcode and edit the PermanentServer parameter (copy and paste the line above)

    open ~/Library/Preferences/com.apple.Terminal.plist

  • Save and close the plist file
  • Open the Applescript application and copy / paste / execute the following code:

    do shell script "defaults read ~/Library/Preferences/com.apple.Terminal.plist"

  • Open Terminal-App and press SHIFT + CMD + K and look in the list of servers

Thanks for this hint here: http://www.cnet.com/how-to/how-to-manually-edit-defaults-plist-files-in-mavericks/

+3
source

The "at" command may trigger a command in the future.

 $ at now + 1 minute /usr/libexec/PlistBuddy -c "Set \"Window Settings\":Basic:shellExitAction 0" ~/Library/Preferences/com.apple.Terminal.plist ^D <<< press CTRL-D job 3 at Mon Apr 24 15:34:00 2017 $ exit 

Now exit all terminals. Wait 1 minute (at least). Now start the terminal and you will find that the setting has been changed.

+1
source

Source: https://habr.com/ru/post/902887/


All Articles