4

I have a window group saved with 3 terminals set up how I like them and I have a shortcut to that opens this window group on my desktop. Now I want to add a startup command (possibly different commands for each window) when each terminal is opened, but I do not want to set a default command for every terminal i start like i know you can. What would be the easiest way to do this?

3 Answers 3

5

So you already have a separate setting for each terminal? You need to edit each of those settings to specify the command to run.

In "Terminal > Preferences > Settings", edit the setting for each terminal, specifying the command for each with "Shell > Startup > Run command".

alt text

When open a terminal from these setting (either individually or as part of a Window Group), it will run the command that you specified in the Settings' startup commands. You can open Window Groups from the "Window > Open Window Group", or configure one to start automatically in "Preferences > Startup".

2

As of Mac OS X Lion 10.7, you can do this without creating separate settings profiles for each terminal. If you create a terminal with Shell > New Command…, Terminal can remember the command when you save it in a window group. When you open a group, any saved commands are run in the corresponding terminal(s).

When saving a window group, Terminal will automatically save "safe" commands†, and you can save all commands by selecting the Restore all commands checkbox.


† "Safe" commands are commands that are reasonable to run without user confirmation, and are automatically restored when Terminal is Resumed. They are also automatically saved in Window Groups. "Safe" commands include any command issued via New Remote Connection, everything listed in /etc/shells, and a short list of common commands: screen, tmux, emacs, vi, vim, nano, pico, top.

This list can be customized with the defaults(1) command (x-man-page://1/defaults). The RestorableCommands preference is a list of strings, each naming a command. In each string you can provide a command name or an absolute pathname (if you only want to allow the command from a particular directory). By default, the commands are only "safe" if they do not include command-line arguments (because arguments may specify destructive operations); to indicate that arguments are allowed, include an asterisk after the command name, e.g. "top *" is in the default list.

For example, to automatically allow emacs with arguments:

defaults write com.apple.Terminal RestorableCommands -array screen tmux 'emacs *' vi vim nano pico 'top *'

For convenience, once you've created the preference setting you can add additional items with -array-add:

defaults write com.apple.Terminal RestorableCommands -array-add nethack
2
  • Nice explanation of this feature. Too bad one cannot link to x-man-page:// URLs on SU.
    – Daniel Beck
    Oct 24, 2011 at 18:58
  • Thanks. Yeah, it would be nice if the x-man-page scheme was accepted by the link parser on StackExchange sites.
    – Chris Page
    Oct 24, 2011 at 19:23
0

@Matt G's answer is good, but an alternative would be to use the open-source iTerm, which has a Bookmarks feature that makes this much easier than having to set up a different terminal profile for each. Since I started using it instead of Terminal.app I haven't looked back. Worth checking out...

1
  • Profiles are Terminal’s bookmarks. You can just duplicate one and put a command in it.
    – Chris Page
    Feb 8, 2012 at 10:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .