Mac “command” to change the background color in a terminal

colorscommand linemac

I want to change the background color of my terminal. setterm doesn't work on a mac? I did find a command which changes the prompt to include the ANSI code?

PS1="\h \w$ \e[0;32m"

But it doesn't take effect immediately, and I want to have it be part of a script which will launch other programs.

Best Answer

You can create an AppleScript script to change the colors of the current Terminal tab. You can use the Script Editor found in Applications/Utilities to create the script. One way to change the colors is to use the color schemes that you could manually select for the Terminal window, but perform the selection in a script. E.g., you could create a script with the following commands using the Script Editor

tell application "Terminal"

   set current settings of window 1 to settings set "novel"

end tell

You could substitute "grass", "ocean", "Red Sands", etc., instead of "novel". Inside the Script Editor click on File and then select Save. Save the script wherever you wish to place it as a .scpt file. Assuming you named the file terminal-colors and placed it your ~/Documents directory, from a Terminal window tab, you can run the script using the osascript command osascript ~/Documents/terminal-colors.scpt

Alternatively, you can set specific background colors of your choosing using values you can find for specific colors at colors.csv. E.g., if you wanted to have a hot pink background, you could use the following commands in your script, instead of the ones above:

tell application "Terminal"

   set background-color of window 1 to {65535, 33667, 49601}

end tell

This is an OSX/MacOS solution that wouldn't be portable to Linux/Unix.

You can see other settings you can change for a Terminal window by opening the Terminal "dictionary" in the Script Editor. Click on File, select Open Dictionary, scroll through the list of dictionaries until you see Terminal.app then click on it to select it and then click on the Choose button. Within the dictionary, click on Terminal Suite then tab to see settings you can change for individual Terminal window tabs.

Related Question