iTerm2 can set itself as the default SSH handler. In its preferences, go to “Profiles”. Create a profile to handle SSH sessions, or select an existing one. In the “General” section, bottom right, you can select which URL scheme this profile should handle:
Select SSH. iTerm2 will ask if it is to set itself up as the default SSH handler:
Confirm and you are done. Happy remoting.
I was curious about the same problem. After reviewing the source code, I found in iTerm2 v1.0.0.20111020 is hard-coded to open a new session as a tab if a session already exists, when it receives nearly any "launch this URL with a handler" command.
My Xcode and Objective-C skills are still rather weak, but if you want to give it a shot I believe the problem is related to the source file iTermController.m. On lines 789 to 870 the launchBookmark:withURL
method has the following code:
// Where do we execute this command?
BOOL toggle = NO;
if (theTerm == nil) {
[iTermController switchToSpaceInBookmark:aDict];
term = [[[PseudoTerminal alloc] initWithSmartLayout:YES
windowType:[aDict objectForKey:KEY_WINDOW_TYPE] ? [[aDict objectForKey:KEY_WINDOW_TYPE] intValue] : WINDOW_TYPE_NORMAL
screen:[aDict objectForKey:KEY_SCREEN] ? [[aDict objectForKey:KEY_SCREEN] intValue] : -1] autorelease];
[self addInTerminals: term];
toggle = [term windowType] == WINDOW_TYPE_FULL_SCREEN;
} else {
term = theTerm;
}
id result = [term addNewSession: aDict withURL: url];
I suspect that when theTerm == nil
, addNewSession
works as expected by launching a new window, since one is currently not running. Perhaps you can modify the code to force the first block to always run, regardless of theTerm
's contents.
I hope this helps!! .. It may be worth filing a bug report or contacting the author if you're still having problems.
Best Answer
If you don't mind using some command-line tomfoolery:
This is from a stack overflow question on a similar topic.
If you want you can even create a new URL handler (or replace the ssh:// one) with a shell script as described at another stack overflow question.
EDIT1: you can get command line args from osascript by using something like the following (taken from the osascript man page):