create new tab from terminal session

The following is one of several ways to create a new terminal window from inside a terminal session


open -a Terminal  ~


Is there a way to create a new tab from inside a terminal session?

Posted on Aug 31, 2019 1:58 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 31, 2019 2:56 PM

You should be able to do this via osascript -e ‘...’ (aka AppleScript)


https://superuser.com/questions/466619/open-new-terminal-tab-and-execute-script


If this does not do it for you, Google “AppleScript Terminal new tab” and you will find other examples.


Note: if your goal is to start Terminal and have Terminal create a dozen tabs, the look at Terminal’s “Window Groups”.


You can create your tabs, then save them as a Terminal Window Group, and set a Terminal Preference that specifies you use your saved Window Group when Terminal starts. Or you can tell Terminal to use a specific Window Group at any time during a Terminal session.


If you create Terminal profiles with a command to execute when creating the Terminal window or tab, such ssh commands to remote systems, where the ssh command runs the GNU screen or tmux command to attach to an already running remote session, then you can start Terminal, have a Window Group run, and in moments you have all your tabs and/or windows created and any profile stored commands executed to attach to remote sessions.


I do this with 4 windows, about 35 tabs 8 macOS local, and the rest going to 8 different Linux, AIX or Solaris systems.


I can launch or quit Terminal to my hearts content, and have my Terminal environment re-established with very little pain. OK, doing the initial profile setup took time, and more than a few experiments, but once finished, it mad my work life easier.


Yea Terminal Window Groups!!!

3 replies
Question marked as Top-ranking reply

Aug 31, 2019 2:56 PM in response to red_wood

You should be able to do this via osascript -e ‘...’ (aka AppleScript)


https://superuser.com/questions/466619/open-new-terminal-tab-and-execute-script


If this does not do it for you, Google “AppleScript Terminal new tab” and you will find other examples.


Note: if your goal is to start Terminal and have Terminal create a dozen tabs, the look at Terminal’s “Window Groups”.


You can create your tabs, then save them as a Terminal Window Group, and set a Terminal Preference that specifies you use your saved Window Group when Terminal starts. Or you can tell Terminal to use a specific Window Group at any time during a Terminal session.


If you create Terminal profiles with a command to execute when creating the Terminal window or tab, such ssh commands to remote systems, where the ssh command runs the GNU screen or tmux command to attach to an already running remote session, then you can start Terminal, have a Window Group run, and in moments you have all your tabs and/or windows created and any profile stored commands executed to attach to remote sessions.


I do this with 4 windows, about 35 tabs 8 macOS local, and the rest going to 8 different Linux, AIX or Solaris systems.


I can launch or quit Terminal to my hearts content, and have my Terminal environment re-established with very little pain. OK, doing the initial profile setup took time, and more than a few experiments, but once finished, it mad my work life easier.


Yea Terminal Window Groups!!!

Aug 31, 2019 7:03 PM in response to BobHarris

@BobHarris I had a tough time using appleScript. I got it to run sometimes but it failed other times when, for whatever reason System Events stoped running. Fortunately the page you pointed me to mentioned a shellscript called ttab which worked flawlessly after I rebooted mac os. Before the reboot it would create a new window rather than a new tab. It's so much simpler than messing around with AppleScript.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

create new tab from terminal session

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.