Can Shortcuts app be automated?

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 ?

UPDATE: The “Delete Shortcuts” action can be made to work conditionally depending on content of input But, it sometimes requires the user to manually choose which shortcut is to be deleted. Not much use then.

Fredrik71, thanks. Sorry, I used the wrong title in my post.

Yes I have browsed the two dictionaries which look the same. But there is just one command and two classes. The “run” command works and getting shortcut and folder properties works. There is no install command but, that can be started by opening an exported shortcut in Finder.

I worked some more on the idea of adding a conditional delete block to a shortcut. It works but only if the shortcut to be deleted is specifically referenced when editing the delete shortcut action. So, if specifically referenced the action looks like this:

But, if it not referenced:

The only difference is the small icon image beside the name of the shortcut to be deleted. If that is not present, running the shortcut will either do nothing or will generate a dialog asking the user which shortcut is to be deleted. So far, I’ve not found a pattern to that – although over time it seems to be doing nothing more often.