A few weeks back I posted some details of working with passing dictionary data between Shortcuts and Scriptable in response to a query. One of these methods was around the use of x-callback-url. Take a look at the CarLog3 script in the following linked post, and have a read through the details of the third method.
cpac, do you care to share your final script? I’m trying to work out this question too, especially now that Scriptable lets me build widgets… I’d love to see what you did.
So I’m stuck here. What I want is actually super simple. I want to just pull in text from Drafts to Scriptable. The ultimate goal is to use that text in a widget. I can’t get that data in at all. What am I doing wrong?
The URL scheme I’m using is:
drafts://x-callback-url/get?uuid=9B3A549D-DA68-4EB1-8FDF-C823AC143E77&x-success=scriptable:///run?scriptName=Text
The Scriptable lines I’m using are:
const successURL = args.queryParameters[“x-success”];
Safari.open(successURL);
I did try to use cpac’s Drafts code but I don’t get what’s going on in the Drafts section of the script.
Oh, I’d be elated if I could get it to do anything at this point. Here’s the complete script I’m working with for now. I get “Expected value of type string but got value of type undefined”
I call the Drafts URL above (drafts://x-callback-url/get?uuid=9B3A549D-DA68-4EB1-8FDF-C823AC143E77&x-success=scriptable:///run?scriptName=Text)
// In Scriptable I have:
const successURL = args.queryParameters[“x-success”];
console.log(successURL)
let alert = new Alert()
alert.title = successURL
alert.message = “This is my alert.”
alert.addAction(“OK”)
await alert.presentAlert()
Do remember to block your code with back ticks, otherwise we have to amend the code to remove all the stuff that Discourse does to it when you post.
Drafts’ call to get doesn’t return x-success. x-success is the URL for Drafts to run on a successful x-callback run. get appends the (URL encoded) draft text to the x-success URL as a parameter called text.
When the Scriptable script runs, we do want to access args.queryParameters, but the result isn’t an array. It’s actually an object with the attributes of the parameters.
Finally, you probably also want to make the draft content the message rather than the title of the alert.
Maybe try it more like this:
let alert = new Alert()
alert.message = args.queryParameters.text;
alert.title = "Draft Content"
alert.addAction("OK")
await alert.presentAlert()
Thanks so much for taking the time with this. That was helpful. I wish I could swing this project—displaying some text from either Drafts or even just from Shortcuts in a Scriptable widget. I’m afraid my skills just aren’t up to it and I can’t find enough Scriptable documentation to work it out. After maybe 10+ hours, learning curve has me beat, I’m afraid.