Simple script to run a shortcut

Hello, I have installed the latest version of the Scriptable App.
There is a new and better doc available (:+1:).
Still I can’t seem to run a simple “hello World” notification that I stored in a “xxx” shortcut into a script.
This code seems to open the shortcuts library, but does not launch the “xxx” shortcut.
What is wrong in the code?

// Running a Shortcut in Script

var cb= new CallbackURL("shortcuts://x-callback-url/") 

cb.open("xxx")

// This seems not to work also 
//var cb=new CallbackURL("shortcuts://x-callback-url/run-shortcut?name=xxx")

// Origanal copy of the new doc
//shortcuts://x-callback-url/run-shortcut?name=xxx&input=input&text=text&x-success=x-success&x-cancel=x-cancel&x-error=x-error

//cb=new CallbackURL("shortcuts://gallery")
 
//cb.open()

Thanx in Advance

You can use something like this to simply run a Shortcut.

const SHORTCUTNAME = "Hello World";
const BASEURL = "shortcuts://run-shortcut?name=";
Safari.open(BASEURL + encodeURI(SHORTCUTNAME));

If you need x-callback specifically, then you can do that like this, but obviously you then need to process any return, consider adding in any inputs as a parameter, etc. as per the Shortcuts x-cllback-url and Scriptable CallbackURL documentation.

const SHORTCUTNAME = "Hello World";
const XCBURL =  "shortcuts://x-callback-url/run-shortcut"
let cb = new CallbackURL(XCBURL);
cb.addParameter("name", SHORTCUTNAME);
await cb.open();

Hope that helps.

1 Like

Yes!!! That did it. Thanx! This means that from a update action on my Alarm Widget, my Alarm ShortCut launches (Finaly), I can choose an Alarm to be set, and the widget update the content.