
However, once we customize the background color (or any other color) the magic does not work any more. There is some “magic” that happens when the system switches to Dark or Light mode. The default “Basic” window profile in Terminal has black text on a white background in light mode and white text on a black background in dark mode. Enter Dark Modeįast forward back to 2018: Along with the rest of macOS, Terminal gained “Dark Mode” in macOS Mojave. I am not the first to discover and use this, Daniel Jalkut and Erik Barzeski have documented this in 2006. Now you can run this AppleScript file like any other script file from Terminal: >. Then open Terminal and change directory to where you save the file and set its executable bit: > chmod +x randombackground
#TERMINAL CHANGE BACKGROUND MAC CODE#
But since we want to use from within Terminal, we will take a different approach: paste the code into your favorite text editor and save it as a text file named randombackground (no extension). You can paste this code in Script Editor and hit the ‘play’ button and watch the Terminal window change. Set the background color of the selected tab of window 1 to newcolor Set blueValue to random number from 0 to maxValue Set greenValue to random number from 0 to maxValue

Set redValue to random number from 0 to maxValue This will set the background color of the current window to pastel pink (salmon?).Īrmed with this knowledge it is fairly straight forward to write a script that will set the background color to a random color: #!/usr/bin/osascript Set background color of selected tab of window 1 to You can also set the background color: tell application "Terminal" The background color is returned as a list of three RGB numbers ranging from 0 to 65535 (2 16 – 1). Get background color of selected tab of window 1 Terminal has a powerful AppleScript library, which allows to read and change (among other things) the background color of a Terminal window or tab: tell application "Terminal" I actually succeeded in creating such a Swift tool, but then, when I worked on connecting the tool with Terminal, I found an even simpler, and arguably better way to do this. Mike’s approach to create the color files with a python script sent me down a rabbit hole to recreate this in Swift. And with the introduction of Dark Mode in macOS it seemed just not useful anymore.

While I have used this for a long time, the limited number of colors has always annoyed me. In an older post, I showed a trick to get random terminal backgrounds from a selection of colors.
