27

I've tried searching for this, and have seen others with similar problems but don't seem to have found an answer anywhere....

I have an AppleScript that I am trying to run over ssh so that I can remotely control my mac. This has worked previously with OSX 10.8 but no longer seems to work since upgrading to 10.9.

The command I am executing is:

ssh <user>@mymac.local "osascript -e 'tell application \"iTunes\" to play'"
  • I have already set up RSA keys so the ssh session opens correctly
  • I am connecting as the same user that the Mac is currently logged in and running under
  • iTunes is running on the Mac with that user at the time the script is launched

The script fails, coming back with:

execution error: iTunes got an error: Application isn’t running. (-600)

Similarly, a number of other scripts that I had previously been using also seem to now be broken on 10.9 with the same error, so this seems to be related to the fact that it's running over ssh, rather than an issue with iTunes or a specific application.

I've tried packaging the applescripts as applications, saving them on the remote Mac, and then opening them from within an ssh session, but this also fails:

ssh <user>@mymac.local
open "~/Desktop/Play Music.app"

(Where 'Play Music.app') is an applescript exported as an app).

This does not report an error within the ssh session, but an applescript dialog appears on the remote mac: enter image description here

I also have several scripts that were scheduled with crontab on my Mac, and these are also failing since upgrading.

I assume this is some sort of security change as part of Mavericks, but I can't seem to find a way to make it work again. Does anyone have any solutions to this?

John Martin
  • 1,502
  • 1
  • 14
  • 25
  • Yep - As I said in the post, iTunes is open at the time. I'm assuming that it has something to do with the ssh shell not being able to see the process, even though it is running with the same user account... – John Martin Nov 13 '13 at 15:33
  • are you able to get a simple dialog to appear ? – mcgrailm Nov 13 '13 at 16:30
  • also what happens if you run the script the same command in the terminal locally on the machine – mcgrailm Nov 13 '13 at 16:44
  • 1
    I can display an alert over ssh. So this works: osascript -e "tell application \"System Events\" to display alert \"Hello\"" The alert appears on the remote screen – John Martin Nov 13 '13 at 17:14
  • If I run the script from the terminal locally on the machine it also works fine. It seems to be running it through an ssh session that's the problem – John Martin Nov 13 '13 at 17:16
  • are both machines on the sam network ? I have tested this and works for me. Is itunes up to date ? – mcgrailm Nov 13 '13 at 17:18
  • Yep - both machines are on the same network. Are you running Mavericks? The problem isn't exclusive to iTunes - the following also fails when run over ssh: osascript -e 'tell application "EyeTV" to activate' comes back with: "execution error: EyeTV got an error: Application isn’t running. (-600)" – John Martin Nov 13 '13 at 17:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41123/discussion-between-mcgrailm-and-john-martin) – mcgrailm Nov 13 '13 at 17:52

15 Answers15

19

Application isn’t running(-600) is an operating system error.

An operating system error is an error that occurs when AppleScript or an application requests services from the Mac OS. They are rare, and often there is nothing you can do about them in a script, other than report them.

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • 5
    Oh there is a thing one can do: restart the machine :) –  Nov 14 '13 at 12:26
  • Rebooting cleared this for me. Very frustrating, but nice that this page exists so we know to try this. Thanks! – e40 Oct 13 '15 at 20:20
  • 1
    When I have this error, I am sure I can see "System Events" in Activity monitor. Wait for some minutes, and the error disappears. – Fish Monitor Jun 06 '16 at 08:43
  • I am trying to develop and debug a script and if I have to keep rebooting every few minutes because the system hoses itself I am going to be *VERY* cross... – Michael Apr 30 '17 at 16:41
  • I had the same problem with Notes and `kill`ing it on the command line worked for me. – Richard Möhn Apr 19 '21 at 22:09
8

Arrrrgh! I don't want this to be the answer, but after trying just about everything, this now seems to be working after a restart.... My guess is that something in appleeventsd got confused (although restarting just appleeventsd on its own didn't fix anything). After a restart osascript seems to be behaving again. I'm still not convinced this is fully fixed, but it does seem to be working for the moment...

John Martin
  • 1,502
  • 1
  • 14
  • 25
  • Agreed, which is why this isn't really an 'answer'... I'll keep an eye on it and see if it breaks again, then maybe I can work out what breaks it and hopefully we'll be closer to fixing it. – John Martin Nov 14 '13 at 17:25
  • I would like a proper answer as well - but this did solve my problem and so I'm upvoting. :) – Joe Aug 28 '14 at 08:56
  • This just happened to me when trying to debug a spontaneous failure of the Dropbox app over ssh. Can't figure out how to fix it... – JeremyKun Jun 03 '15 at 04:15
  • Oh, this is another very upsetting thing from Apple :( First time I got this in the beginning of 2019 (mid-January) on High Sierra 10.13.1 (upgraded much earlier and definitely have not had any issues for many months). By the way this is a VM on VMware Fusion and suddenly I found it [VM] to be down. I turned it back on and immediately started having this issue. After visiting this page I restarted VM and it cleared it for a while, but today I have faced it again. Then it cleared after a few hours without a restart. Currently looking on how to diagnose this better, since this getting annoying.. – RAM237 Feb 06 '19 at 14:37
7

For me, it was Apple Entitlements in Xcode.

Specifically,

com.apple.security.temporary-exception.apple-events

Set it as an Array

Then add two items to it.

com.apple.finder

com.apple.iTunes

See: My applescript doesn't work any more when I upgrade my OS X to 10.9

Community
  • 1
  • 1
Jordan
  • 1,879
  • 3
  • 19
  • 25
4

Apple Script may not be the issue. Assistive devices could be what is causing this.

Enable access for assistive devices and applications by opening System Preferences > Security & Privacy > Privacy > Accessibility and check the applications you want to allow access.

Dennis Hoer
  • 3,039
  • 2
  • 23
  • 34
  • This was absolutely the case for getting Sublime Text to cooperate with Applescript. Glad I scrolled down to your answer. – Chris Redford Jun 14 '18 at 05:07
2

for me this happened when I tried to open gitk. Changing back to the branch I was on before, and gitk was able to open again

Yo Ludke
  • 2,149
  • 2
  • 23
  • 38
2

On my computer, with an uptime of 162 days, killing appleeventsd fixed the problem. I think appleeventsd and long uptimes is a bad combination.

d-b
  • 695
  • 3
  • 14
  • 43
0

System Events is a really finicky asshat component of OS X. Here is my method for getting around that dreaded "Application isn't running -600" error:

set app_name to "System Events"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & "$
if the_pid is not "" then do shell script ("kill -9 " & the_pid)

tell application "System Events"
-- activate  
end tell

I kill "System Events" with a kill -9 and then relaunch it.

benmarbles
  • 11
  • 2
  • 1
    Just a follow-up. This piece of code seems to make applescripts run more reliably locally, but I still can't get osascript to run over SSH. osascript can't interact with any active applications and it's god damn infuriating. – benmarbles Jun 10 '14 at 12:40
0

@benmarbles code seems to be missing something at the end of line 2 -- it won't even compile.

Anyhow, I've seen the same issue with "Image Events" and I solved it with a simplified version of that script. Here's how I handle it:

tell application "System Events" to set thePID to (unix id of process "Image Events")
set killCMD to ("kill -9 " & thePID) as text
do shell script killCMD with administrator privileges

Replace Image Events with System Events to kill that process instead. The System Events process keeps itself alive, so there's no need to do anything to relaunch it.

0

I got the same error when I was unable to do GUI Scripts, but changing the System Preferences > Security & Privacy > Privacy > Accessibility settings for that specific app and adding a delay 0.5 between each line corrected it!

jrbedard
  • 3,662
  • 5
  • 30
  • 34
S.Doe_Dude
  • 151
  • 1
  • 5
0

I was confused by this message "for System Events" not working in newer versions of Mac OS X from the command line:

osascript -e 'tell application "System Events" to display dialog "Build finished"'

It turns out the syntax of Applescript is (changed to?) just:

osascript -e 'display dialog "Build finished"'
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
0

Hello from 2k19 :) The approach below has helped to me

tell app "app_name"
    launch
    delay 2
end tell
tell app "app_name"
    do something usefull
end tell

or

osascript -e "tell app \"app_name\"" -e "launch" -e "delay 2"-e "end tell" -e "tell app \"app_name\"" -e "do someting usefull" - e "end tell"
0

For my issue resolved by enable access for AEServer by opening System Preferences > Security & Privacy > Privacy > Accessibility

George Zhang
  • 371
  • 1
  • 2
  • 9
0

You will also get this error if you run the script as the wrong user via ssh - make sure you are logged in as the same user you want to script.

0

I killed the "System Events" process from Activity Monitor and then my ssh script worked. "System Events" was restarted as a result. I'm guessing it just got into a messed up state.

0

For me, the line:

tell application "Contacts"

failed with the error -600 only if the Contacts app was already open (most of the time it worked, but I noticed it only failed when the app was running).

I have added:

killall Contacts

in the bash (or zsh) script calling osascript and now I don't get the issue any more.