X-callback in Alfred Workflows?

I’ve been trying to figure this out, but I’ve hit a bit of a dead end with my knowledge. I have an Alfred app workflow that takes a variety of input variables and then feeds a JXA script that loads a few templates, does a bunch of processing, and then creates a project in Things 3 and a related Drafts document.

When creating the Drafts document, I’m creating it using the following code:

var draft_x = 'drafts5://x-callback-url/create?tag=[MyTag]&tag=' encodeURComponent('[My Other Tag]') + '&text=';
var xcurl = draft_x + encodeURIComponent(draft_text);
var noteID = app.openLocation(xcurl);

The app referred to is var app = Application.currentApplication() which I believe would be the osascript instance Alfred is using to execute the script.

That said, what I’d like to do is throw this at the end:

app.openLocation('drafts5://x-callback-url/open?uuid=' + noteID.uuid);

But noteID doesn’t recieve any parameters back from the x-callback. Is there any way to have it return the UUID to the script running within Alfred so that I can open directly to the note? Ideally this could end up working, then I could embed a link to the draft directly within my Things project.

1 Like

I use xcall with Alfred in some Ulysses workflows. I believe the author is one of the Ulysses developers. Rob Walton’s Alfred workflow for Ulysses also uses it.

See also this thread

And here’s a working (at the time) example of xcall in an Alfred script filter (in python):

Thanks for your suggestion. I was able to get the behaviour I wanted by adjusting my code and using xcall. The changes really were minimal. All I had to do was change:

var noteID = app.openLocation(xcurl);

To:

var noteID = JSON.parse(app.doShellScript('/Applications/xcall.app/Contents/MacOS/xcall -url "' + xcurl + '"'));
app.openLocation("drafts5://x-callback-url/open?uuid=" + noteID.uuid);

It might be a little overkill for what I’m doing, but I’m glad to have it working. I’ll be able to use this to do some other nice automation work within similar workflows. Thanks for sharing!

Awesome - glad it worked easily.