Change font of Terminal programmatically w/o restarting

At home I've got a nice big display that unfortunately does not have the same resolution as my retina macbook does.

I'd like to use a pixel-font on the low-res screen and a nice smooth one on the retina screen. To do this I've set up a script that listens to an event when the display is connected.

I've set up two profiles in Terminal.app, one for the low-res screen and one for the retina screen.

Is there a way to make a profile the "default" profile (eg using applescript) without restarting Terminal.app (otherwise defaults com.apple.terminal ... would have done it)

The following script works by changing the current default profile (so it's not entirely what I need, but might work if I find the names of all the settings I want to change):

#!/usr/bin/env osascript -l JavaScript
function run (argv) {
  var terminal = Application('Terminal');

  terminal.defaultSettings.fontName = 'creep';
  terminal.defaultSettings.fontSize = 16;

  // these don't seem to work
  // because I do not know their names, and it's hard to debug guessing them
  // terminal.defaultSettings.fontAntialiasing = false;
  // terminal.defaultSettings.fontHeigthSpacing = 0.8;
}

I'd have to write a script to revert the changes


Solution 1:

Okay, after some fooling around in AppleScript editor (it has this nice thing called dictionary that shows you all available commands for a given App) I settled for this script:

#!/usr/bin/env osascript
on run {name}
  tell application "Terminal"
    set default settings to settings set name
    set current settings of tabs of windows to settings set name
  end tell
end run

Make it executable (chmod u+x change.applescript) and run it, passing in the name of the profile to activate:

./change.applescript creep

This will:

  • change the default profile, so all new windows will use it
  • change the profile of all tabs of all windows to the new profile, so open terminals get to use it too!