I am trying to automate opening of multiple tabs, naming each tab (printf "\e]1;${TAB_NAME}\a") and doing a cd and maybe something else in each tab. Can that be done either in a startup script or, better yet, configured within Terminal itself?


You can try this.

You can use the Terminal Profiles to give each tab its own profile. This way, you can set the shell command for each tab individually.

And you can save the window group (tabs) so they will open on Terminal launch.

Example of set up

Set up your tabs in a window, i.e., cd to the directories in each tab as desired.

Then, go to the Terminal Preferences and to Settings Tab menu:

  1. Select the Basic Profile.
  2. Click the + button at the bottom. This will duplicate the profile.
  3. Name the new profile (for example, home).

Repeat steps 1 - 3 as many times as the number of tabs, and name each of them with unique names.

In my example, I will have 'home' and 'work'.

Now, for my 'home' profile, I will:

  1. Select the Shell tab.

  2. Check 'Run command'.

  3. Set the command string to cd ~

  4. Check 'Run inside shell'.

For each profile, I will repeat steps 5 - 7, changing the cd command accordingly.

enter image description here

In my tab named 'Home Dir', I will:

  1. Ctrl + click on the window to get the contextual menu, and select 'Show inspector'.
  2. Select the 'settings' tab
  3. Set its profile to the 'home' profile.

For each tab, I will repeat steps 1 - 3, changing the profile accordingly.

Now, my Home tab's profile should be the 'home' profile and my tab named 'Work Dir' profile should be the 'work' profile.

enter image description here

Now using the Windows Menu "Save Windows As Group".

Check the checkbox - "Use window group when Terminal starts".

enter image description here

I have tested it as best I can and this set up works.

Each tab opens in the cd's to its own directory. And does so on Terminal start up.

I like this so much, I am going to use it myself.

You must log in to answer this question.

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