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.
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!
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.
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.
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 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:
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.