0
OS: MacOS Catalina 10.15.1
Language: Swift
IDE: Xcode

I'm trying to run an apple script with module AppleScriptObjC in my macOS app, and the apple script code is showed below:

-- test.applescript
script test
    property parent : class "NSObject"

    to testDialog()
        log "This is log msg."
        tell application "Finder"
            display dialog "Hello World"
        end tell

        display notification "This is notification Content" with title "This is notification Title"
    end testDialog
end script

After calling testDialog(), the log message showed, but dialog "Hello World" did not appear. And I got an error Finder got an error: Application isn’t running. (error -600).


Updated

When using the app name instead of "Finder", "Hello World" will display correctly. However, display notification still won't work.

  • You're not showing the actual function call (e.g., `test's test()`) or it's context. I'd suggest renaming the script object (it's odd to have a script object with the same name as one of its handlers), and that you make the call to "System Events" not "Finder". System Events.app is less buggy for scripting. – Ted Wrigley Feb 28 '20 at 14:35
  • @TedWrigley, thank you for your reply. I have changed the function name from `test` to `testDialog`. Hope that it will be more accurate. – Artis24106 Feb 29 '20 at 06:12
  • `"System Events"` didn't work too, and the error message was the same. Using the name of the app worked though ("Hello World" showed up correctly). – Artis24106 Feb 29 '20 at 06:18
  • 1
    Error -600 seems to be a sandbox issue. You have to add the `NSAppleEventsUsageDescription` key in info.plist – vadian Feb 29 '20 at 07:18
  • Thank you so much @vadian ! It worked perfectly. – Artis24106 Mar 02 '20 at 17:11
  • Adding `NSAppleEventsUsageDescription` to `Info.plist` did not work for me — any ideas how to solve this in 2022? I always get an `Application isn’t running` error, even if sandbox is turned off. – ixany Sep 11 '22 at 19:50
  • @ixany Try [this](https://stackoverflow.com/a/76204182/10446972), it should work. – AgentBilly May 08 '23 at 20:50

0 Answers0