Run a Shortcuts app shortcut with ASObjC

AppleScript has the ability to run a shortcut as follows:

tell application "Shortcuts Events" to run shortcut named "Open File"

Just out of curiosity, I wondered if this could be done with ASObjC, and, if so, could you give an example. Apparently, it is done with Swift by way of a “URL scheme”. Thanks!

Fredrik71. Thanks for the script suggestion, which worked well. However, my question is whether there is ASObjC that is functionally equivalent to the AppleScript open location command. I had previously tried the following, but it didn’t work.

use framework "AppKit"
use framework "Foundation"
use scripting additions

set theURL to "shortcuts://run-shortcut?name=calculate&input=text&text=2%20*%203"
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
theWorkspace's openURL:theURL

Fredrik71. That fixes that issue and the script now works. Many thanks.

However, when I run the script, the Shortcuts app interface is shown, which doesn’t happen when the Shortcut Events app is used. For testing:

use framework "AppKit"
use framework "Foundation"
use scripting additions

-- runs shortcut but does not show Shortcut app
tell application "Shortcuts Events" to run shortcut named "Show Dialog"

-- runs shortcut but shows Shortcut app
set theURL to "shortcuts://run-shortcut?name=Show%20Dialog"
set theURL to current application's |NSURL|'s URLWithString:theURL
set theWorkspace to current application's NSWorkspace's sharedWorkspace()
theWorkspace's openURL:theURL

-- runs shortcut but shows Shortcut app
set theURL to "shortcuts://run-shortcut?name=Show%20Dialog"
open location theURL

My Show Dialog shortcut is:

Show Dialog.shortcut (21.4 KB)

The Show Dialog shortcut is very simple and I thought it might be best just for testing.

But in daily use, that’s not a workable solution. For example, I ran the ASObjC solution by way of the Script Menu, and the Shortcuts app was displayed along with the dialog. It should only show the dialog.