I work on a lot of tabs in terminal at a given time. Sometimes, I get tabs mixed up and accidently run commands on tabs I am not supposed to.

To simplify this, I wish to write some script, that on each new tab creation, comes with a random background color (not the text background, the window background), so that I can easily identify the tabs I was working with.

Any suggestions ?


4 Answers 4


The built-in default "Solid Colors" profile randomly selects a background color for each new terminal.

It works by setting the background image to a folder of images, each of which is a solid color. To choose different colors (or patterns, etc.) you can place a collection of images in a folder and set a profile to use the folder in

Preferences > Profiles > [profile] > Text > Background > Image:

Another feature of profiles is that if you create a new terminal with Shell > New Command or New Remote Connection it will look for a profile with a matching name and select that profile. It will look for a match of the entire command string, a partial match of the command name and arguments starting from the left, and it will also try to interpret the profile name as a regular expression.

This means you can name a profile “ssh” to have it selected for any ssh command, or “ssh hostname” for ssh commands whose first argument matches hostname, for example.

  • That's a pretty sweet hack, great find! The way it's worded in there, it's not very intuitive that an entire directory can be selected, let alone that it will randomly grab from there.
    – dhempler
    Commented Dec 16, 2015 at 13:36
  • @dennis.hempler The built-in “Solid Colors” profile exists to demonstrate this capability. In general, the built-in default profiles each attempt to demonstrate various appearance features, like translucency, blur, etc. I recommend trying each of them out.
    – Chris Page
    Commented Dec 16, 2015 at 13:49

I would highly recommend using iTerm2 I'm still finding cool new features. I don't know about a truly random background color, but I know you can change your settings based on user, host, file system location. Though, that feature may still be in beta.

Yes, that's still in beta:

Automatic Profile Switching Using the Shell Integration feature, you can have iTerm2 switch profiles depending on what you're doing. For example, you can define a profile that's always used when you ssh to some hostname. Or when your username is root. Or even when you're in a particular directory.


Here's a .zlogin file I use to cycle the terminal through the 8 "standard" colors, based on the tty number:

if [[ $TERM_PROGRAM == "Apple_Terminal" ]]; then
        N=$(( ${$(tty)##*[!0-9.]} + 0 ))
        R=$(( $N & 1 * 4000 + 2000 ))
        G=$(( $N & 2 * 2000 + 2000 ))
        B=$(( $N & 4 * 1000 + 2000 ))
        osascript <<EOD
tell application "Terminal"
  set background color of selected tab of front window to {$R, $G, $B}
end tell

Save that as your user's .zlogin file and it should only run when an interactive login shell is started, so a new tab.

The first tab will be black, but after that, red, green, yellow and so on.

Alternatively, it wouldn't be hard to extend this to pick a color out of a list of presets, either by extending the Zsh or the AppleScript parts.


If you want permanent customization, look at the nice details here: https://apple.stackexchange.com/a/99453/118237

For temporarily change, all you need to do is right-click on the terminal tab, choose "Inspect Tab", and make change via Info or Settings tabs.

enter image description here enter image description here

BTW, this information is based on Terminal Version 2.7.3 (388.1.1).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .