AppleScript prompted by Xojo App fails

Running current version of Xojo/MacOS/AppleScript

I have an app written in Xojo that instructs Keyboard Maestro to run various macros that have been written in that application. Xojo accomplishes this feat by running an imbedded AppleScript.

The AppleScript itself is very straight-forward. You are asking Keyboard Maestro (which is a commercial application) to run a specific macro that it knows about and you pass it a single parameter to give that macro some particular bit of information. The AppleScript looks like this:

For some time, this worked just fine. It has been working on my own machine for a long time (years).

Then a user told me that when he tried it nothing happened. As best I can tell, this is related to permissions under Privacy & Security in System Settings. When I installed everything de novo on a new machine, I ran into the same problem.

When I ran the AppleScript on the new machine using Terminal it worked. The first thing that it did was ask for permission.

I gave it permission and it worked correctly.

However, when I had my Xojo app run this same AppleScript nothing happened. It did not ask for permission and the AppleScript, I assume, did not run.

On my personal machine, looking at System Settings :: Privacy & Security :: Automation

The Xojo app is ASK_Palette and there it is under Automation. If you look for details, it shows you

None of this is seen on the new machine.

With this sleuthing, I believe the problem is that the Xojo app does not ask for and therefore does not get permission to cover the use of the AppleScript. All I can say is that this must have worked sometime in the past. The app continues to work fine on my own machine.

Does someone understand what this issue is and how to solve it?

You may give a try to “tccutil reset All com.yourcompany.yourapp" in the Terminal.

You might want to have a look at this example project: GitHub: jo-tools/applescript-automation: Using AppleScript for Automation with Xojo

Things have changed with macOS 10.14 :wink:

At the very least you’ll need an Info.plist with NSAppleEventsUsageDescription.

The linked example also shows:

  • How to determine if the application has permission for AppleEvents / Automation (AEDeterminePermissionToAutomateTarget).
  • Explains how to deal with the permission results.
  • In case you determine the application has no permission:
    How to open System Preferences at Privacy - Automation (so that the user can allow the app).

I’m not sure, if this is on Macs with Apple Silicon only, but on my M1-Mac i also need to codesign the debug build, without it, the permission request does not show up. I use an Xojo IDE-Script like this for the debug-build:

Var dbg as String = ""
if debugBuild then dbg = ".debug"

Var result As String

result=DoShellCommand("codesign -f -s ""Developer ID Application: Your Name (SXXXXXXXXX)"" " + CurrentBuildLocation+ "/" + PropertyValue("App.MacOSXAppName") + dbg + ".app")

The app needs the NSAppleEventsUsageDescription AND a full codesign to do AppleScripts. And internet connection.

1 Like

You are saying that it CANNOT run this AppleScript successfully if it is not on the Internet??

Sorry, my bad. If you develop then you have to have internet connections. Only a built app works without internet.

I had major problems with the internet connection in the last weeks. You can’t even start Xojo if you want plugins loaded. And for the codesign you need to have internet connection.