« Religion makes the stupid, part #32498 | Main | Oh lord, here we go again »

Today on Stupid AppleScript Tricks

I know I'm reinventing a wheel here, but it took like five minutes, so who cares. Anyway, one thing that makes me bonkers about Apple Remote Desktop is that while I can run Unix commands on a remote machine with it, what I can't do is easily select a machine and just open an SSH session to it.

Well, now I can. Here's the script:

set theSSHList to {}
tell application "Remote Desktop"
     set theComputers to the selection
     repeat with x in theComputers
          set the end of theSSHList to Internet address of x
     end repeat
end tell

tell application "Terminal"
     repeat with x in theSSHList
          do script "ssh username@" & (contents of x)
     end repeat
end tell

It's pretty simple. We initialize theSSHList, then grab all the selected computers in Remote Desktop. (Note...if you have Apple Remote Desktop open, there is always a selected computer as long as there's a computer in the window to select, so this will tend not to fail unless you're pointing at an empty computer. For obvious reasons, it won't work on a computer you haven't added to Apple Remote Desktop yet.)

We process the list of computers, and dump their IP addresses into theSSHList.

Next is to interate through theSSHList, and open a new ssh session for each item in theSSHList.

This won't bring Terminal to the front, by the way. I don't tend to like that, but if you do, then just add an "activate" command right after "tell application "Terminal"" and Terminal will merrily pop to the front.

Put that in your scripts menu and you can now easily pop ssh windows to Apple Remote Desktop computers when you need.


Technorati Tags:
, , ,


Posted by John C. Welch at 09:11 | Permalink


Comments

Warning for Notes users: The commenting system uses HTML.
I know this will be scary for some of you, especially Notes fans. However, open standards, rah-rah.
If you want to use less-than or greater-than signs, or other similar charachters that HTML reserves,
you'll simply have to learn to do it the HTML way. Luckily, HTML is kind of popular, no matter what
your re-educators have told you, and you can easily find help on the intertubes.

Thanks for the script! Here's a version for iTerm if anyone wants:

set theSSHList to {}
tell application "Remote Desktop"
    set theComputers to the selection
    repeat with x in theComputers
        set the end of theSSHList to Internet address of x
    end repeat
end tell

tell application "iTerm"
    set myTerminal to (make new terminal)
    tell myTerminal
        repeat with x in theSSHList            
            set mySession to (make new session at the end of sessions)
            tell mySession
                exec command "ssh username@" & (text of x)
            end tell
        end repeat
        activate
    end tell
end tell

Posted by: Arthur Author Profile Page | May 7, 2008 10:21 AM

Added a small dialog display to get a username. Might be useful to others who work in multiple locations.

set theSSHList to {}
tell application "Remote Desktop"
set theComputers to the selection
repeat with x in theComputers
set the end of theSSHList to Internet address of x
end repeat
end tell

tell application "Terminal"
repeat with x in theSSHList
set username to display dialog "Username:" default answer "admin" buttons {"OK"} default button {"OK"}
set username to text returned of username
do script "ssh " & username & "@" & (contents of x)
end repeat
end tell

Posted by: Reed L Author Profile Page | February 11, 2009 5:28 PM

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?


digital.forest Where Internet solutions grow

There, a PayPal Button.

 
Family
The Artwork of Melissa Findley
Diane Francis @ the National Post Eric Francis @ the Calgary Sun

Apple Amazon Links
Apple Mac OS X Server 10.5 [Unlimited]

Apple Mac OS X Server 10.5 [10-Client]

Apple Mac OS X 10.5 Leopard

Apple Mac OS X 10.5 Leopard [5-User Family Pack]

Amazon Book Links
Legacy of Ashes: The History of the CIA

The Donnas: Bitchin'

Wizards at War (The Young Wizards, Book 8)

The Demon's Sermon on the Martial Arts

The Collected Stories of Arthur C. Clarke

JavaScript and Ajax for the Web, Sixth Edition

Awakening Warrior: Revolution in the Ethics of Warfare

FOB Links

Mac Web Writers

Techie Links

Review Victims