script that ssh ?

Hi out there, I’m completely new to this, so have patience :slight_smile:

Is it possible to make a script that open terminal or iTerm and ssh to a remote host and execute some commands and then quit when finished?

First of all welcome!

Then I want to point out that there is search on macscripter. There are several duplicate posts about how to execute an ssh command on a remote machine. Read post #5 in this topic that demonstrates how to work with it.

ah thanks. I searched for ssh, but didnt find anything. But I might be retard. :wink:

Hi there,

I’ve tried it myself before via the “Do shell script” command, but it would require multiple arguments.

This might work though (I have no idea, I’m just writing from what’s in my head, not testing it)


on ssh(computer_name,user_name,pass_word)
tell application "System Events" to activate
tell application "Terminal" to activate
tell application "System Events"
activate
keystroke ("ssh " & user_name & "@" & computer_name) as string
keystroke return
delay 2
keystroke "y"
keystroke return
delay 2
keystroke pass_word
keystroke return
delay 2
end tell

With any luck, this will work in compiled form. I’m to tired to do it. Tell me if this works.

Sorry, I forgot an end block. Here’s the “correct” version. I can’t actually test it yet, because I only have one computer with me right now, so I’m still not sure if it actually works.


on ssh(computer_name, user_name, pass_word)
	tell application "Terminal" to activate
	tell application "System Events"
		activate
		keystroke ("ssh " & user_name & "@" & computer_name) as string
		keystroke return
		delay 2
		keystroke "y"
		keystroke return
		delay 2
		keystroke pass_word
		keystroke return
		delay 2
	end tell
end ssh

ssh(computer_name, user_name, pass_word)

Good luck!