Applescript to restore foreground color doesn't work

0

When I attempt to restore a MacOS terminal window's default color by executing the following:

osascript -e "tell application \"Terminal\" to set current settings of window 1 to settings set \"Homebrew\""

the Terminal background color is restored to the Homebrew default, but not the foreground color. Doing it explicitly also has no effect:

osascript -e 'tell application "Terminal" to set normal text color of window 1 to {47802, 61423, 16448, 0}'

Oddly, when I execute an ls (LSCOLORS are on) immediately after the above, colors are restored to the correct state. Any idea what might be going on or how to fix it?

Also, there's nothing in the PS string to change the color as part of the prompt. Hitting return a couple times has no effect. Neither does executing something harmless like echo. Thanks!

aholub

Posted 2018-09-06T02:53:17.070

Reputation: 36

Answers

0

This is interesting, because I cannot reproduce your error. What system are you running ? For reference, here are my relevant system details:

System info: AppleScript version: "2.7", system version: "10.13.6" (High Sierra)

One thing to note, is that current settings and normal text color are properties that are ascribed to tabs of Terminal, and not windows. Therefore, one thing you could try is:

osascript -e "tell application \"Terminal\" to ¬
          set current settings of tab 1 of window 1 to ¬
          settings set \"Homebrew\""

However, if I'm being honest, I'm not expecting this to solve your problem, since your piece of code works just fine on my system.

CJK

Posted 2018-09-06T02:53:17.070

Reputation: 384

As expected, Didn't work :-) (It's also AS 2.7 on 10.13.6)

I did track things down a bit more. The color change is in a function that changes colors, ssh's into a remote system, and then when ssh terminates, restores the colors. The remote system's shell does mess with the colors in its PS2 variable (which is why I want to put them back). I found that if I remove the color changes from the remote system PS2, that things work correctly, so it seems to be some odd interaction with ssh. – aholub – 2018-09-07T00:37:38.023