I use Alfred (http://www.alfredapp.com/) to speed things up on my mac and it is a brilliant bit of software. I pay for the powerpack and have written a little bit of applescript to allow me to ssh to a server from the launcher.

I have it set up to so that “ssh server username” will connect to server as username. If you don’t put it a username it will default to “default”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
on alfred_script(q)
	set tmp to splitString(item 1 of q, " ")
 
	set server to item 1 of tmp
 
	if length of tmp is 2 then set login to item 2 of tmp
	if length of tmp is 1 then set login to "default"
 
	set command to "ssh " & server & " -l " & login
 
	tell application "Terminal"
		do script command
	end tell
end alfred_script
 
to splitString(aString, delimiter)
	set retVal to {}
	set prevDelimiter to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {delimiter}
	set retVal to every text item of aString
	set AppleScript's text item delimiters to prevDelimiter
	return retVal
end splitString

Phil (see comments) wrote a version that can handle ports as well. I’ve changed it slightly as something appears to have changed within Alfred which was causing it to ignore the username passed in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
on alfred_script(q)
	set tmp to splitString(item 1 of q, " ")
 
	set server to item 1 of tmp
 
	(* Split at colon delimiter *)
	set server to splitString(server, ":")
 
	(* Does it contain a port? If not just roll with it. *)
	if length of server is 2 then
		set serverport to item 2 of server
		set serverip to item 1 of server
		set server to serverip & " -p " & serverport
	end if
 
	if length of tmp is 2 then set login to item 2 of tmp
	if length of tmp is 1 then set login to "default"
 
	set command to "ssh " & server & " -l " & login
 
	tell application "Terminal"
		do script command
	end tell
end alfred_script
  • http://pgourley.com Phillip Gourley

    I sometimes need to SSH to the IP and your code struggles with ports, I’ve tweaked it a little to work with ports too.

    Grab the code here.

    http://pastebin.com/7z9DMYSn

    Thanks for sharing!