Skip to content

Repository files navigation

AppleScript-Automation

Xojo example project

License: MIT

Description

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.
    Requirement: Check the following Build Settings (without these, nothing will work at all.):
    • Build Settings - macOS:
      PropertyList Key NSAppleEventsUsageDescription
    • Build Settings - macOS: Sign:
      Entitlement enabled: com.apple.security.automation.apple-events
  • 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.

ScreenShots

Automate Terminal.app by executing a Shell command in Terminal.app
ScreenShot: AppleScript-Automation - Automate Terminal.app

Determine Permission to automate Terminal.app
ScreenShot: AppleScript-Automation - Determine Permission to automate Terminal.app

Xojo

Requirements

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 2026r1.2
  • API 2

How to use in your own Xojo project?

  1. Configure the following Build Settings:
    • Build Settings - macOS:
      PropertyList Key NSAppleEventsUsageDescription (Edit to fit your app's purpose.)
    • Build Settings - macOS: Sign:
      Entitlement enabled: com.apple.security.automation.apple-events
  2. 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.
  3. Use the provided Methods in the Modules in a similar way to this example project.
  4. Codesign (with hardened Runtime) and/or Notarize your application:
    Make sure to have the Entitlement enabled: com.apple.security.automation.apple-events
    • set Xojo Build Settings: macOS -> Sign
    • or use Xojo2DMG

About

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.

Contact

E-Mail    Follow on Facebook    Follow on Twitter

Donation

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.

PayPal Dontation to jotools

About

Using AppleScript for Automation with Xojo

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages