1

I'd like to have my MacOS terminal window change background color while ssh is started, and change back to default when ssh finishes. There are a few approaches to this, the one I'm pursuing is to make a little bash function which first uses AppleScript to send a message to the Terminal Window telling it to change profile, then runs ssh, then sends another message via AppleScript telling Terminal to set the profile back. This approach is described in many posts on the SO family of sites. It relies on a line like this:

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

This works well if ssh exits while the terminal window in question is the focused terminal window. However, if ssh exits because the remote host closed the connection, it's quite likely that your local window focus has moved to a different terminal window, which means that "window 1", which seems to be 'focused window', is no longer the same terminal window, so you get funky behavior.

Can I grab something like a current terminal window ID at the start and re-use that later ?

0 Answers0