Can I run Scriptable scripts via x-callback-url and pass parameters?

Can I run Scriptable scripts via x-callback-url and pass parameters when doing that?

Reason for asking: I have a lot of actions in Launch Center Pro that add tasks to Remember The Milk (RTM) via its Smart Add syntax. Currently I use Pythonista and the RTM API, but Pythonista is not updated that often, so an alternative/fallback would be nice.

In fact, I’m currently able to do this via Drafts and its Scripts but I feel Scriptable might be more suitable.

For reference an example of an LCP action:

pythonista://rtm-api-script?action=run&argv={{Task #List #@context @Location}}
1 Like

In the settings cog for every Scriptable script there’s an x-callback url - and if you investigate the args section of the documentation that should help you too!

3 Likes

Did not see the x-callback-url part in the cog… Thanks!

However, the “args” documentation only mentions another context (action extension), not x-callback-url. Also I don’t see how to pass arguments.

Maybe that part is not supported (yet)?

(Or am I again not searching good enough?)

I’m not 100% sure it will work, but I’ll create a test script later today and call it via URL - a simple test and then we’ll know!

Appreciated.

I can’t test myself right now; I can’t get my iPad out of Recovery Mode after a failed Beta 10 update… :cry:

You’re right. The URL in the script settings can be used to run a script. However, you’ll have to use the URLScheme API to read the query parameters. I’ve been considering moving these into args.queryParameters but I’m not yet convinced that’s the best solution.

You can open a URL like this:

scriptable:///run?scriptName=Untitled%20Script&foo=hello&bar=world

And then have your script read all query parameters using URLScheme.allParameters():

As for x-callback-url, Scriptable provides an API to open another app. If you want to do it the other way, i.e. open Scriptable to run a script and return a response to a third party app, it should be easy to implement yourself.

When initiating a x-callback-url flow from another app, you should find the query parameters x-success, x-error and x-cancel in URLScheme.allParameters(). Call those URL schemes with the parameters you want to return to the app.

3 Likes

Thanks Simon! This is much appreciated :smiley:

Thank you! I should be able to get this working, if I install iOS 12 Beta again…

Only way to get my iPad properly booting again was installing iOS 11.4.1 and setting it up as a new device. But I’m glad it’s not really bricked :smile:

Might try (iOS 12 Beta 10) again this weekend.

BTW: very happy that Scripts are stored in iCloud! (I did not backup my RTM script before the Beta 10 fiasco)

Got it working! :smile:

Took me more time than needed because I did no see I needed 3 slashes (usually it’s only 2), but then I noticed I could copy the URL from within Scriptable and that one had 3…

I’m glad to hear that you got it working! :smiley:

I just wanted to comment on the three slashes. It’s actually not that uncommon to use three slashes in a URL scheme on iOS. The reason developers wants to do this is to differentiate the intent based on the host of the URL scheme. A URL scheme is constituted by the following elements:

  • protocol
  • host
  • path
  • query parameters

protocol://host/path?queryParameterKey=queryParameterValue

When we have three slashes after the protocol, it means that the host is empty.

protocol:///path?queryParameterKey=queryParameterValue

Scriptable uses the empty host for “public” URL schemes in order to shorten them. Internally, I use named hosts for other URLs, e.g. URLs used by the action extension.

Other apps that use this convention include Tweetbot which has URL schemes for various interactions, e.g. opening the profile of a user with tweetbot:///user_profile/username.

2 Likes

The OmniGroup also do this with their apps! Technically it’s the “right” way to do URL schemes :slight_smile:

2 Likes

Presumably the host is not meant to be of any value (pun intended).

1 Like