Monday, October 22, 2018

#1 2015-07-09 10:17:50 am

timmrogers
Member
Registered: 2015-06-04
Posts: 9

Applescript and Apple Remote Events

I'd like to send a notification from an Apple OS X Server to my laptop using Apple Remote Events.

Some example code that I found online suggested that something like this might work:

Applescript:


tell application "System Events" of machine "eppc://172.16.1.1"
   tell process "Notification Center"
       display notification "Foo”
   end tell
end tell

but it gives me this error:

Syntax Error
Application isn't running.

I have enabled Apple Remote Events on my laptop, and provided a valid password.

Any suggestions? Should this be possible?

Thank you.

Offline

 

#2 2015-07-09 12:22:30 pm

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2807
Website

Re: Applescript and Apple Remote Events

There is a known "bug" with remote event and the application system events. IIRC StefanK once posted a clever solution to launch system events (which I'm using on one of my servers; scripting addition commands are executed by systems events on a remote machine).


Applescript:

-- code is written on a non-mac so it's not tested
set theMachine to "eppc://172.16.1.1"
using terms from application "Finder"
tell application "Finder" of machine theMachine
get every process -- this will launch "System Events" if it is not running
end tell
end using terms

using terms from application "System Events"
tell application "System Events" of machine theMachine
tell process "Notification Center"
display notification "Foo”
end tell
end tell
end using terms

p.s. if it still doesn't work, since Yosemite Apple has made a terrible update according to remote application names. You have to target them by their localized name and no longer to their real application name. System Events has to be targeted on the remote as Systeem-Events on a Dutch machine for instance.

Last edited by DJ Bazzie Wazzie (2015-07-09 12:24:05 pm)

Offline

 

#3 2015-07-09 01:01:39 pm

timmrogers
Member
Registered: 2015-06-04
Posts: 9

Re: Applescript and Apple Remote Events

Thanks for the reply!

And I think that I understand the issue and what we need to do.

I wasn't able to make the script work, however. Both the original and my slightly modified version - using "end using terms from" rather than "end using terms" - gave this error:

Expected “"” but found end of script.

This is the script that I am using:

Applescript:


set theMachine to "eppc://172.16.1.1"

using terms from application "Finder"
   tell application "Finder" of machine theMachine
       get every process
   end tell
end using terms from

using terms from application "System Events"
   tell application "System Events" of machine theMachine
       tell process "Notification Center"
           display notification "Foo”
       end tell
   end tell
end using terms from

Offline

 

#4 2015-07-09 01:23:13 pm

timmrogers
Member
Registered: 2015-06-04
Posts: 9

Re: Applescript and Apple Remote Events

It seems that AppleScript doesn't like the "of machine theMachine" clause in this script.

Applescript:


tell application "System Events" of machine theMachine
   tell process "Notification Center"
       display notification "Foo"
   end tell
end tell

This works fine.

Applescript:


tell application "System Events"
   tell process "Notification Center"
       display notification "Foo"
   end tell
end tell

although it shows the notification on the local machine, of course.

But the version with the "...of machine theMachine" gives a syntax error.

Am I missing something that should be obvious?

Offline

 

#5 2015-07-10 05:31:16 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2807
Website

Re: Applescript and Apple Remote Events

First of all sorry for the wrong end using terms from lines, I wasn't behind a machine with an script editor right then but just showing the procedures on how to launch system events. For you other problem I assume you have an non-English machine? When using remote apple events you need to target the remote application by it's localized name and not it's actual name like you would targeting applications locally. On my machine to target System Events locally I use "System Events" no matter what the language of the OS is, but remotely I need to target it as "Systeem-Events" (Dutch).

Applescript:

set theMachine to "eppc://xxx.xxx.xxx.xxx"
using terms from application "Finder"
   tell application "Finder" of machine theMachine
       get processes
   end tell
end using terms from

using terms from application "System Events"
   -- localized name for System Events
   set localizedAppName to "Systeem-Events"
   tell application localizedAppName of machine theMachine
       display notification "Hello World!" with title "Foo"
   end tell
end using terms from

Last edited by DJ Bazzie Wazzie (2015-07-10 05:39:17 am)

Offline

 

#6 2018-05-11 02:52:32 pm

ealbert
Member
Registered: 2007-02-20
Posts: 2

Re: Applescript and Apple Remote Events

-- Just fixed some misspellings, this should work as is once you replace IP address
-- The remote machine requires Remote Apple Events be ON
-- You will have to enter a user name and password that is available
--    in the Sharing > Remote Apple Events dialog box on the remote machine

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set RemoteMac to "eppc://XXX.XXX.XXX.XXX"
using terms from application "Finder"
    tell application "Finder" of machine RemoteMac
        get processes
    end tell
end using terms from

using terms from application "System Events"
    -- localized name for System Events
    set localizedAppName to "System Events"
    tell application localizedAppName of machine RemoteMac
        display notification "Hello World!" with title "TEST"
    end tell
end using terms from

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)