Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to use a specific iTerm2 tab

Hello!


I have a 3rd party application that opens remote sessions to a few different hosts by running a command for each of the hosts I wish to connect to.


What I would like to do is use an Applescript wrapper in the provided command line area to check and see if there is an iTerm tab open with a specific profile already. If there is, select that tab. If not, open a new tab with the specific profile and select that tab. Within that specific tab, create a spit screen window, name that split screen and run the remote session command line inside that split screen.


The idea is that any time this application tries to open a new connection, it will always do so within one tab so they are always easy to find since they are all collected within one single tab. The only way I can think to do that is to use a special iTerm2 profile name.


If that doesn't make any sense, here's maybe a bit of a better example:


# argv: telnet 192.168.18.1

if there is not an iTerm2 tab open with the profile name VIRL, then

open a new iterm2 tab with the profile name VIRL

select the tab with the profile name VIRL

create a vertical split screen within that tab

name this split screen argv[2] # 192.168.18.1

execute argv[1] args[2] # telnet 192.168.18.1


So if this wrapper is called 4 times, the first call with argv telnet 1.1.1.1, the second call with argv telnet 2.2.2.2, the third argv telnet 3.3.3.3 and the last argv 4.4.4.4, there will be 4 split screens all open inside one single tab identified by the profile name VIRL. split screen 1 is named '1.1.1.1' and has just executed `telnet 1.1.1.1`. split screen 2 is named '2.2.2.2' and has just executed `telnet 2.2.2.2`. split screen 3 is named '3.3.3.3' and has just executed `telnet 3.3.3.3`. split screen 4 is named '4.4.4.4' and has just executed `telnet 4.4.4.4`


Make sense? 🙂


Thanks in advance for any pointers!

Posted on Nov 30, 2015 4:53 AM

Reply
1 reply

Applescript to use a specific iTerm2 tab

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