Launch Applescript on remote machine?

Is it possible to launch a script on a remote machine? I need as part of a script running on Machine A to call a script running on Machine B.

tell application "Finder" of machine "eppc://user:pass@MachineB.local"
	do shell script "osascript '/Users/user/Desktop/someScript.scpt'"
end tell

When I try I get the error: Finder got an error: A privilege violation occurred.

If you are going trying to execute the script through the shell, it makes more sense to use Remote Login/ssh instead of Remote Apple Events:

do shell script "ssh user@MachineB.local osascript '/Users/user/Desktop/someScript.scpt'"

Note that you need to setup ssh to do non-interactive authentication or use sshkeychain.

Another possibility would be to use the do script command:

tell application "AppleScript Runner" of machine "eppc://user:pass@MachineB.local"
   do script "/Users/user/Desktop/someScript.scpt"
end tell

Thank you, that looks promising, however I get the error:
AppleScript Runner got an error: Cannot find process on host

I’ll research the other suggestion you gave about SSH and keychains, I’ve never done those things.

Hi,
I guess that shell scripts doesn’t work at all on remote machines (for security reasons).
Talking to a remote machine with AppleScript is based on Remote Apple Events
and shell scripts don’t send Apple Events

A way to run a script on a remote machine is to save is as application
and run it with for example

tell app "Finder" of machine remoteMachine to open application file "test.app" of desktop

Hi,

unlike local machines, a tell block doesn’t launch the target application automatically on a remote machine.
You have to launch the application explicitly by opening the application file id with the Finder.
because the Finder is the only application, which is always running

Here is an alternative solution which does NOT require AppleScript Runner:

tell application "Finder" of machine "eppc://user:pass@MachineB.local"
	set s to load script "/Users/user/Desktop/someScript.scpt"
	run script s
end tell

Another option that works well for me, is to go to ‘Preferences’ in your Mail app. and set up a rule to run a script based on what’s written in the Subject line of an incoming email.

Thank you. I tested with a simple script that just pops up a Display Dialog, but the dialog appeared on my local machine, not the remote machine where I need to send the command to launch the script. This surprised me.

StefanK, I’m sorry I missed your post.

I tried your suggestion as it sounds perfect but I get this error:

Can’t get application (application file “test.app” of folder “Desktop” of folder “jessie” of folder “Users” of startup disk of application “Finder” of machine “eppc://user:pass@machineb.local”) of desktop.

“test.app” is there on the Desktop exactly where the error says it is.

try this, I’ve tested it with a different user on the same machine.
It checks if the user is present.
In this case the name of the application and the UID is included in the eppc string


property user_name : "myuser" -- admin username
property pass_word : "mypass" -- admin password
property uid : "502" -- user id of remote user

set host_name to host name of (system info)
set s to "eppc://" & user_name & ":" & pass_word & "@" & host_name & "/Finder?uid=" & uid

if check_user(s) then
	using terms from application "Finder"
		tell application s to open application file "test.app"
	end using terms from
end if

on check_user(eppc)
	using terms from application "Finder"
		try
			tell application eppc to get (desktop as string)
			return true
		on error
			return false
		end try
	end using terms from
end check_user

StefanK, I used your script but set the host_name to the host name of the remote host and I was able to call my test script!

This is encouraging, thank you!