Skip to Main Content
Mac OS X for Unix Geeks
book

Mac OS X for Unix Geeks

by Ernest E. Rothman, Brian Jepson
September 2002
Beginner to intermediate content levelBeginner to intermediate
216 pages
7h 43m
English
O'Reilly Media, Inc.
Content preview from Mac OS X for Unix Geeks

Customizing the Terminal on the Fly

You can customize the Terminal in shell scripts using escape sequences or AppleScript commands. xterm users may be familiar with using the following to set the xterm’s title:

echo '^[]2;My-Window-Title^G'

Mac OS X’s Terminal accepts this sequence as well.

Tip

^[ is the ASCII ESC character, and ^G is the ASCII BEL character. (The BEL character is used to ring the terminal bell, but in this context, it terminates an escape sequence.) The escape sequences described here are ANSI escape sequences, which differ from the shell escape sequences described earlier. ANSI escape sequences are used to manipulate a Terminal window (such as by moving the cursor or setting the title). Shell escape sequences are used to tell the shell to treat a metacharacter, such as |, as a literal character rather than an instruction to pipe standard output somewhere else.

To type the ^[ characters in tcsh, use the key sequence Control-V Escape (press Control-V and release, then press the Escape key). To type ^G, use Control-V Control-G. The vi editor supports the same key sequence; Emacs uses Control-Q instead of Control-V.

You can capture this escape sequence in a shell alias:

alias settitle 'echo -n "^[]2;\!*^G"'

Then you can change the title by issuing this command:

settitle your fancy title here

You may want to package this as a shell script and make it available to everyone who uses your system, as shown in Example 1-3.

Example 1-3. Setting the Terminal title in a shell script ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mac OS X For Unix Geeks, 4th Edition

Mac OS X For Unix Geeks, 4th Edition

Ernest E. Rothman, Rich Rosen, Brian Jepson
Mac OS X Hacks

Mac OS X Hacks

Kevin Hemenway, Rael Dornfest
Mac OS X in a Nutshell

Mac OS X in a Nutshell

Jason McIntosh, Chuck Toporek, Chris Stone

Publisher Resources

ISBN: 0596003560Errata Page