Launch Remote Application via Remote Apple Events

Hi All,

I read in another post that a remote application must already be running to send it Apple Remote Events.

http://bbs.applescript.net/viewtopic.php?id=3727

However I have found that since the Finder is always running you can tell Finder to open the application. I wanted to launch an Automator App on my web server to run a perl script to update an index database.


	tell application "Finder" of machine "eppc://Username:Password@IP_Address"
		open file "Server HD:Applications:iTunes"
	end tell

When I run this iTunes launches on the other machine. I use it like.


	tell application "Finder" of machine "eppc://Username:Password@IP_Address"
		open file "Server HD:Users:admin:Documents:Rebuild IF Index-Quick"
	end tell

The last item “Rebuild IF Index-Quick” is the name of my Automator App.

Be sure Remote Apple Events is on for the remote computer.

Cheers,
MT

Hi MT,

you can check whether an application is running on the remote machine
and open it if necessary with this (e.g for iPhoto)

tell application "Finder" of machine "eppc://Username:Password@IP_Address"
	using terms from application "Finder"
		if "iPhoto" is not in (get name of every process) then
			open application file id "com.apple.iPhoto"
		end if
	end using terms from
end tell

I Like It! It will work even better for what I need to do. The Automator workflow I’m triggering on the remote machine can take 5-10 min to run so this approach will be aware of the apps status.

Question:
Are there other options to reference the application ? (e.g. “iPhoto”)

open application file id "com.apple.iPhoto"

I need to trigger an Automator app named “Rebuild IF Index”

Thanks for the input.

MT

Hi MT,

if your Automator workflow app is a “real” app, you can get the application file id with

get bundle identifier of (info for file "path:to:Rebuild IF Index")

I’m getting an error on (get name of every process) the term “name” is highlighted

AppleScript Error
Finder got an error: can’t find process on host. (-600)

It does this trying it with iPhoto as well as the app I’m trying to use it with.

Any Ideas?

Mtorrance,

I don’t see why you would burden Finder with a request that essentially is for “System Events”.
Also, “using terms from” allows you to substitute the local app’s AS dictionary to simplify compilation over the network (you’re using it the other way around!)

So I’d suggest this:


using terms from application "System Events"
tell application "System Events" of machine  "eppc://Username:Password@IP_Address"
set procNames to name of the processes
end tell
end using terms from

Hello,

Good point about system events. I have switched to this on the local machine


tell application "System Events" of machine "eppc://User:Pass@IP_Address"
		open file "Server HD:Users:admin:Documents:Studio Scripts:Check Rebuild Status"
end tell

which triggers this on the remote machine


set isRunning to "false"
	
	tell application "System Events"
		set procNames to name of the processes
	end tell
	
	if (procNames contains "Rebuild IF Index-Quick") then
		set isRunning to "true"
	end if
	
	if (isRunning = "false") then
		tell application "System Events"
			open file "Server HD:Users:admin:Documents:Studio Scripts:Rebuild IF Index-Quick"
		end tell
	end if

I couldn’t pull the process names from the remote machine so I just trigger the remote machine to check it’s running processes and launch it if it is not running. Thanks for the input

MT

Hi,

this cannot work actually because you’re addressing System Events of the localhost instead of the remote machine.
This should work

tell application "System Events" of machine "eppc://User:Pass@IP_Address"
	if  ((get name of the processes) does not contain "Rebuild IF Index-Quick") then
		open file "Server HD:Users:admin:Documents:Studio Scripts:Rebuild IF Index-Quick"
	end if
end tell

Hi Eelco,

although process is no property of the Finder’s dictionary it works anyway

Agree,
but Finder can be a busy little guy doing very little (especially with network scripting) so why use that as handover…

Hi Stefan,

The below script

set isRunning to "false"
   
   tell application "System Events"
       set procNames to name of the processes
   end tell
   
   if (procNames contains "Rebuild IF Index-Quick") then
       set isRunning to "true"
   end if
   
   if (isRunning = "false") then
       tell application "System Events"
           open file "Server HD:Users:admin:Documents:Studio Scripts:Rebuild IF Index-Quick"
       end tell
   end if

was running on the remote machine so it worked OK, it didn’t need ( of machine “eppc://User:Pass@IP_Address” ) because the script is running on the machine that I needed to get the processes from, but I think I like your approach better as it doesn’t require two scripts and is more effecient. I added it to the end of my Automator app and it works great!

Thanks A Bunch,
Mark