Jump to content

Scriptability on macOS Monterey (macOS 12)


Recommended Posts

Scriptability matters for Alfred Workflows, so this is a short thread on what we know about scriptability on the new macOS version. Discussion and new data is welcome; I’ll strive to keep this top post up to date with the most relevant information.

 

Python, Perl, and Ruby survived in the same versions as Big Sur, but PHP was removed.


Shortcuts is coming to macOS, but it doesn’t mean the end of AppleScript yet:

 

Quote

Advanced scripting
Pro users can enable AppleScript and shell script compatibility.

 

The Shortcuts app will scriptable, though the functionality isn’t yet available. It will also have a command-line tool:

 

Quote

Known Issues

  • The Shortcuts command-line tool doesn’t support signing. (74999291)
  • (…)
  • Shortcuts isn’t scriptable. (78609585)

 

On June 8 there was a session going more in-depth into Shortcuts. Notable points:

 

“We also added two new automation types for Focus and Sound Recognition”.


“By the way, if your app integrates with file providers, these new Files actions will automatically work with the files that your app provides”.


“We also have a new file format that lets you distribute Shortcuts as files“. (…) “This means that you can distribute your own Shortcuts on your website or in your app”. Which means we may be able to distribute Shortcuts as complements to Workflows. For M1 Macs, that may open a window to distribute everything needed to control iOS apps from Alfred.


However, it’s unclear if we’ll need a ($99/year) Developer Account to distribute them in useful form, since they mention signing: “Shortcuts files are notarized by Apple to make sure they’re safe”. (…) “a new mode for sharing Shortcuts privately” (…) “Shortcuts files are signed with the identity of the person who sent them. If you need to re-sign a Shortcut, you can use the new Shortcuts command-line tool”.


“Shortcuts has full support for AppleScripts and Shell Scripting”. Not dead yet!


“Shortcuts is the future of Mac automation”. Taken in isolation; it’s a scary implication the other technologies are destined for the bin. But in context, they’re talking speficially about replacing Automator.


“There’s a Shortcuts command-line tool which lets you list and run Shortcuts in your Shell Scripts or command-line tools”.


“If you develop an app or a script that would benefit from the ability to run Shortcuts, you should use the Scripting interface. By communicating with the “Shortcuts Events” process, your app can get a list of shortcuts that the user has set up, as well as start running one. In AppleScript, you can accomplish this by telling the “Shortcuts Events” process to run a shortcut by name”:

 

tell application "Shortcuts Events"
    run the shortcut named "Make GIF"
end tell

 

“Finally, macOS Monterey also includes a command-line tool that can list shortcuts and run them by name. If you have command-line tools or scripts, they can integrate with Shortcuts via this interface”.

 

OVERVIEW: Command-line utility for running shortcuts.

USAGE: shortcuts <command>

OPTIONS:
  -h, --help              Show help information.

SUBCOMMANDS:
  run                     Run a shortcut.
  list                    List your shortcuts.
  view                    View a shortcut in Shortcuts.
  sign                    Sign a shortcut file.

  See 'shortcuts help <subcommand>' for detailed help.

 

Edited by vitor
Link to comment

Updated the top post with information from the session. There are quotes with links to timestamps, how to call Shortcuts from AppleScript, and the help form the command-line tool.

 

For Alfred Workflow developers, the beginning and end are the most interesting; the middle is how to build update an app to support a Shortcut.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...