My applet has an Automator Service which has one action, to run an AppleScript. The applet has code which installs and uninstalls the Service.
The Service converts into a Shortcut without alteration and works well. The Shortcut seems faster. Unlike Automator workflows, a Shortcut can be added to the Dock and the System Menu as well as the usual Services Context Menu.
So, I am trying to develop AppleScript code which installs and uninstalls a Shortcut. So far, no luck. This code will open an exported shortcut in the Shortcuts app allowing the user to install:
tell application "Finder"
open <path to exported shortcut>[name].shortcut"
end tell
There is probably a better way, but using Finder works. I tried System Events but got an error: “System Events cannot open files in the “Shortcut” format.”
Opening an exported shortcut in Finder launches the Shortcuts app and an “Add Shortcut” dialog which tells the user some detail about the shortcut (e.g. “Appears in Menu Bar”; “Appears in Services Menu”). Thus, the user can choose to cancel the install process which is good. This makes for a reasonable install process for my users.
Developing an uninstall process has not been so easy. I can’t find a way to delete a shortcut using AppleScript. I have tried this:
tell application "Shortcuts"
delete shortcut "[name]" -- FAILS "AppleEvent handler failed."
end tell
One possibility is to use the “Delete Shortcuts” action. That action can delete any shortcuts including itself. However, I’ve not yet found a way to invoke that action conditionally via AppleScript.
Has anyone been able to automate Shortcuts ?