Skip to content

Instantly share code, notes, and snippets.

@JamesHenry
Created October 29, 2021 10:50
Show Gist options
  • Save JamesHenry/75292ec21a02dcb8918a96c018d47a37 to your computer and use it in GitHub Desktop.
Save JamesHenry/75292ec21a02dcb8918a96c018d47a37 to your computer and use it in GitHub Desktop.
/** @type {import("@johnlindquist/kit")} */
// Menu: Say Hello World Shortcut
// Description: Trigger macOS Monterey Shortcut from Script Kit
// Author: James Henry
// Twitter: @MrJamesHenry
/**
* I have created a Shortcut on my Mac running macOS Monterey called
* "Say Hello World".
*
* There are a couple of options available when it comes to invoking
* it programmatically (whether via Script Kit or in general).
*/
/**
* OPTION 1:
*
* You can use the `shortcuts` CLI that is preinstalled on macOS
* Monterey to run named Shortcuts.
*/
await $`shortcuts run "Say Hello World"`;
/**
* OPTION 2:
*
* You can use AppleScript to communicate with the "Shortcuts"
* application on macOS Monterey to run named Shortcuts.
*
* NOTE: I first tried to communicate with "Shortcuts Events" per this
* video from WWDC 2021, but it does not work:
* https://developer.apple.com/videos/play/wwdc2021/10232/?time=1539
*/
await applescript(`
tell application "Shortcuts"
run the shortcut named "Say Hello World"
end tell
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment