The title says it all.
For the curious: I have a PowerKey Pro 650, a scriptable, USB-controlled, 6-outlet power bar connected to my dual-core G5. I’d like to be able to control it from my MBP as well, and it’s easy to set up a tunnel from one to the other – I do it when I want to VNC from the laptop to the G5. A VNC session would also accomplish what I want to do from the G5 screen, but I’d rather embed my task in a complete script that established the tunnel and ran a script through it (as opposed to starting one on it), and closed the tunnel.
As I see it, you have two basic approaches to this.
One is to store the script on the server and use another script to connect to the server and launch the script remotely.
The second is to store the script on the client and have it send Remote Apple Events to the process on the server that manages the PowerKey.
Off hand I think the first approach is probably easier - it’s no harder than:
ssh you@ip.of.server.net /path/to/remote/script
This will ssh to the server and run the script at /path/to/remote/script. If the PowerKey is AppleScript-based then a few simple osascript commands should suffice.
Thanks, Camelot. I agree that saving a script on the server and starting it remotely is probably more efficient, but sending the script through a tunnel works too:
I establish the ssh tunnel and then add this after the prompt from the other machine:
(where the try/try again method assures it goes – the PowerKey does miss occasionally)
/usr/bin/osascript <<EOT
tell application "PowerKey Daemon"
try
set HP to level of outlet 2 of unit "PKP"
on error
set HP to level of outlet 2 of unit "PKP"
end try
if HP = 0 then
set HP to 100
else
set HP to 0
end if
try
set level of outlet 2 of unit "PKP" to HP
on error
set level of outlet 2 of "PKP" to HP
end try
end tell
EOT
et voilá – the printer starts (or stops). Easy enough.