Xojo example project
There used to be a time where any application just could execute AppleScripts to Automate other applications such as: tell application X to do Y
.
That's no longer the case starting with macOS 10.14
. It's become a bit trickier to do that with a Xojo built application, since not everything is built in.
This example project shows:
- How to use AppleScript for Automation in a Xojo built application by providing an
Info.plist
withNSAppleEventsUsageDescription
.
Without that, nothing will work at all. - 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).
Additionally:
- Check if an Application is running (find .app by BundleIdentifier )
and if not: launch it.
Automate Terminal.app
by executing a Shell command in Terminal.app
Determine Permission to automate Terminal.app
Xojo is a rapid application development for Desktop, Web, Mobile & Raspberry Pi.
The Desktop application Xojo example project applescript-automation.xojo_project
is using:
- Xojo 2023r3
- API 2
-
Drag the example
Info.plist
into your project.
Edit it and change theNSAppleEventsUsageDescription
to fit your app's purpose. -
To determine Automation-Permission and opening System Preferences at Privacy - Automation
- copy-and-paste the Module
modAppleScriptUtils
into your project.
If you want to check for an .app running (and launching it if required) then additionally
- copy-and-paste the Module
modMacOsApplications
into your project.
- copy-and-paste the Module
-
Use the provided Methods in the Modules in a similar way to this example project.
-
If you are CodeSigning (with hardened Runtime) and/or Notarizing your application:
Make sure to have theEntitlement
enabled:com.apple.security.automation.apple-events
Juerg Otter is a long term user of Xojo and working for CM Informatik AG. Their Application CMI LehrerOffice is a Xojo Design Award Winner 2018. In his leisure time Juerg provides some bits and pieces for Xojo Developers.
Do you like this project? Does it help you? Has it saved you time and money?
You're welcome - it's free... If you want to say thanks I'd appreciate a message or a small donation via PayPal.