Receive a value from Scriptable in Shortcuts


#1

I’m looking for a way to receive a value from Scriptable in Shortcuts action.
args.all do the way from Shortcuts to Scriptable. Is there any command in reverse direction?


#2

Unfortunately passing data between Shortcuts is not supported by iOS. However there are two workarounds that you can look into.

  1. Use the pasteboard. Both Scriptable and Shortcuts supports manipulating the pasteboard. In Scriptable this is done with the Pasteboard API. When you run a script, you can put a string or image into the pasteboard and read it in Shortcuts. The benefit of this approach is that it doesn’t require Shortcuts or Siri to open scriptable. The next approach does.
  2. Use x-callback-url. Shortcuts supports opening a x-callback-url and processing the result when a third party app invokes x-success. In Scriptable, you can use the URLScheme API to get the x-success URL and the Safari API to open the URL. It looks like the following:

Shortcut

Scriptable script

let params = URLScheme.allParameters()
let baseURL = params["x-success"]
let url = baseURL + "?hello=world&foo=bar"
Safari.open(url)

Can input be passed to Scriptable from Shortcuts app?
#3

I appreciate your detailed guide to work around this issue! I’ll adapt x-callback-url way because it looks straightforward than pasteboard-way.
Feel wretched Apple putting a limit on interconnectivity between Shortcuts and third-party apps. Anyway, we can do this!


#4

Hi, I was looking into a way to pass arguments into the script and as you guys noted above it can’t be done at the moment. However I saw that there is this shortcut action for Pythonista where they can pass input into sys.args

Any idea how they do that? I’m going to try to use it a little bit see if I can find something but you guys work on the scriptable app so you probably have better insight.


#5

It’s built into the URL scheme for Pythonista, which is what Shortcuts is making use of, and sys is a Python module that Pythonista is making use of, with sys.argv being a standard Python construction.

In effect the details above on the x-callback-url for Scriptable are doing the same thing, just grabbing the data string directly. I think you should be able to write a function to process it like the sys module in Pythonista is doing. Just split the return with the parameter returns in the URL.