SSH Remote Desktop Selection

A while back I was asked by a colleague if I could automate starting a number of SSH connections based on the current selection in ARD. This may seem pointless given that you can run UNIX commands in ARD but it is not. With SSH you get an interactive shell; quite different from just being able to send commands and receive a sample of the response!

The applescript is below. I launch the script using QuickSilver but you could put a copy in your Dock or in your Scripts folder (~/Library/Scripts) if you use the Scripts menu item.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
tell application "Remote Desktop"
	set the_result to display dialog ¬
		"Username: " default answer ¬
		"admin" with icon 1 ¬
		buttons {"Cancel", "Connect"} ¬
		default button "Connect"
 
	set button_pressed to button returned of the_result
	set text_typed to text returned of the_result
 
	if (count of text_typed) > 0 then
		set ssh_command to "ssh " & text_typed & "@"
	else
		set ssh_command to "ssh "
	end if
 
	if button_pressed is "Connect" then
		set sel to selection
		repeat with i from 1 to length of sel
			set this_ip to Internet address of item i of sel
			tell application "Terminal"
				activate
				do script ssh_command & this_ip
			end tell
		end repeat
	end if
end tell

Leave a Reply