Change OSX Terminal Settings from Command Line

Menu

Changing fonts and colors should be easy, also with terminals. Alas, neither iTerm2 nor OSX Terminal seem to have an easy way of doing this: you need to define a new profile or change some presets of the current profile. This is often an overkill.

Various solutions exists on the Internet, typically based on Applescript. Starting from these works, I have put together a few functions that allow to change colors and fonts using Emacs’ color names. For a solution based on JavaScript and working on Yosemite, look at the comments below or visit Fotsies Technology Blog.

Instructions:

  1. Grab colors.csv (a Github gist) and save it in your home. The file contains all colors known to Emacs (with M-x list-colors-display) with the corresponding representation used by Applescript.
  2. Grab the setcolors.bash (another Github gist) and add its content to your .bash_profile (or source the file, if you prefer)

You are done! You can now change colors from your terminal using the following commands:

For instance:

$ set_foreground_color wheat
$ set_background_color gray10
$ set_font "Oxygen Mono" 12

Now that you can change colors using a bash function, some opportunities arise. For instance, you can programmaticaly change the terminal colors when connecting to a different host.

Date: 2014-07-16 Wed 00:00

Author: Adolfo Villafiorita

Created: 2020-04-03 Fri 18:43

Validate