Applescript fails with error (-600) when launched

2019-01-14 12:06发布

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?

9条回答
一夜七次
2楼-- · 2019-01-14 12:22

@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.

查看更多
3楼-- · 2019-01-14 12:22

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!

查看更多
地球回转人心会变
4楼-- · 2019-01-14 12:23

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.

查看更多
\"骚年 ilove
5楼-- · 2019-01-14 12:29

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"'
查看更多
成全新的幸福
6楼-- · 2019-01-14 12:36

Apple Script is not the issue.

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

More info: https://support.apple.com/en-us/HT202866

Jacob Salmela also has created a utility to do this from command line:

http://jacobsalmela.com/os-x-yosemite-enable-access-assistive-devices-command-line/

查看更多
Viruses.
7楼-- · 2019-01-14 12:37

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

查看更多
登录 后发表回答