isometry / alfred-tty

Alfred Workflow to quickly switch between or close iTerm windows, tabs and panes based on title and tty
MIT License
105 stars 0 forks source link

How to use the action.js script to go to a specified iTerm tab? #4

Closed nikitavoloboev closed 6 years ago

nikitavoloboev commented 7 years ago

I want to make a hotkey that would open the second tab of iTerm when activated.

I tried to transfer the main part of the code like so :

function run(args)
{
var iterm = Application(getenv("iterm_application", "com.googlecode.iterm2"));
var win = iterm.windows[0];
var tab = win.tabs[2];
var ses = tab.sessions[0];
tab.select()
}

Also I call this JXA from Keyboard Maestro like so :

2017-10-04 at 13 22

I am quite new to JXA but I am kind of confused by this.

Thank you for any help.

isometry commented 6 years ago

Unfortunately, windows aren't zero-indexed. You don't need to worry about sessions (which are indexed by uuid). Something along the following lines should work:

var iterm = Application("com.googlecode.iterm2");
var fgWinId = iterm.windows.id()[0];
var fgWin = iterm.windows.byId(fgWinId);
var secondTab = fgWin.tabs[1];
secondTab.select();
fgWin.select();
iterm.activate();