knurling / ServiceStation

Service Station
37 stars 1 forks source link

Support macOS Monterey Shortcuts #59

Open pkamb opened 3 years ago

pkamb commented 3 years ago

Announced today at WWDC, Shortcuts are coming to macOS:

Shortcuts arrives on the Mac to help users automate everyday tasks and achieve peak productivity. Just like on iPhone and iPad, Shortcuts on Mac lets users quickly accomplish tasks with the apps they use the most. With a rich gallery of pre-built actions designed just for Mac, users can instantly share files, make animated GIFs, and more. Power users looking to take things further can use the Shortcuts Editor on Mac to customize shortcuts to match their workflows. Shortcuts is integrated throughout macOS, including the menu bar, Finder, Spotlight, and even hands-free with Siri — making it easy to run shortcuts no matter which app the user is in. Users can easily import existing Automator workflows into Shortcuts and be up and running right away.

https://www.apple.com/newsroom/2021/06/macos-monterey-introduces-powerful-features-to-get-more-done/

Service Station should support launching Shortcuts in addition to AppleScript and Automator Workflows.

pkamb commented 3 years ago

WWDC 2021 session video:

Meet Shortcuts for macOS

https://developer.apple.com/videos/play/wwdc2021/10232/

At 24:58 they cover running Shortcuts from a Mac app:

Finally, if you'd like to run Shortcuts from your app or command-line tool, there are two methods to consider.

First, Shortcuts exposes a scripting interface which lets Mac apps and AppleScripts list and run Shortcuts. Additionally, there's a Shortcuts command-line tool which lets you list and run Shortcuts in your Shell Scripts or command-line tools, as well.

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.

Using the Scripting Bridge framework, you can ask the Shortcuts Events process to run a shortcut directly from your Swift or Objective-C apps. For sandbox apps, you'll need to add an entitlement called com.apple.security.scripting targets. In order to access the list of shortcuts and run them, you'll need to add the com.apple.shortcuts.run target.

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.