Skip to content

Latest commit

 

History

History
114 lines (77 loc) · 3.36 KB

README.md

File metadata and controls

114 lines (77 loc) · 3.36 KB

tp — Terminal Profile Switcher for macOS Terminal.app

A pair of zsh commands for switching Apple Terminal.app color profiles ("settings sets") from the command line.

  • tp — change the profile of the active tab (immediate, visible right now).
  • tpd — change the default profile used by all new windows.

Verified working on macOS, Terminal.app, zsh.


Install

# 1. Put the script somewhere on your machine
mkdir -p ~/.config/tp
curl -fsSL https://raw.githubusercontent.com/leifulstrup/tp/main/tp.zsh -o ~/.config/tp/tp.zsh

# 2. Wire it into your shell (append to ~/.zshrc)
cat >> ~/.zshrc <<'EOF'
autoload -Uz compinit && compinit          # enables tab-completion
source ~/.config/tp/tp.zsh
EOF

# 3. Load it into the current shell
source ~/.zshrc

The first time it runs, macOS shows a one-time prompt — "Terminal wants to control Terminal" — click OK.


Installed files

File Purpose
~/.config/tp/tp.zsh The tp + tpd functions and tab-completion. This is the source of truth.
~/.zshrc Enables completion (compinit) and sources ~/.config/tp/tp.zsh. Add these two lines if the file already exists.

A copy of tp.zsh lives in this folder (tp.zsh) as a backup/reference. The live copy that actually runs is ~/.config/tp/tp.zsh.


Usage

tp — active tab

Command Action
tp List all profiles; ← marks the current one
tp 10 Set the active tab's profile by its list number
tp Ocean Set by name (case-insensitive)
tp ocea Partial name match also works
tp <Tab> Tab-complete profile names

tpd — default for new windows

Command Action
tpd List profiles; ← marks the current default
tpd Pro Set the default profile (by name) for new windows
tpd 12 Set the default by number
tpd <Tab> Tab-complete profile names

(Named tpd — "tp default" — rather than tp! so no quoting is needed; ! would otherwise trigger zsh history expansion.)


How it works

Both commands drive Terminal.app via AppleScript (osascript):

  • List profiles: get name of every settings set
  • Active-tab profile: set current settings of selected tab of front window to settings set "NAME"
  • Default profile: set default settings to settings set "NAME"

The functions read the profile list newline-separated (robust against names containing commas), support numeric / exact / partial matching, and print the result to stderr.

First-run permission

The first AppleScript call may show a one-time macOS prompt: "Terminal wants to control Terminal" — click OK. It won't ask again after that.

Scope / limitations

  • Terminal.app only. iTerm2 and other terminals use a different mechanism and are not supported.
  • tp affects the front window's selected tab — the terminal you're actively looking at.

Activate in a running shell

New windows pick everything up automatically. For the current window:

source ~/.zshrc

Profiles

The commands list whatever profiles ("settings sets") exist in your Terminal.app Preferences. The stock macOS set includes: Basic, Grass, Homebrew, Man Page, Novel, Ocean, Pro, Red Sands, Silver Aerogel, Solid Colors, Clear Light, and Clear Dark.


License

MIT