Your script hasn't returned any results

I have a script which is sending a file to an outside API to get processed and then loading the results into a second service. I runs typically for 6-8 seconds per time, most of that time spent in await for the three API calls to respond.

When I run this in the background with Shortcuts I regularly get a dialog saying something like you haven’t returned any results. I have Script.complete() at the end, and I do return results. Is there any way round this to fix it? It’s easy to reproduce. Build a new Scriptable script as follows:

var milliseconds = 7900
var date = new Date()
do { curDate = new Date() }
while( curDate-date < milliseconds )
log( "done" )
Script.setShortcutOutput(true)
Script.complete()

Then setup a shortcut to call it with “Run In App” and “Show When Run” both switched off. It’ll show a dialog saying:

Could Not Run Script: Script completed without presenting UI, triggering a text to speak or outputting a value. If this is intentional, you can manually call Script.complete() to gracefully complete the script.

If you turn the delay down to 7.85 seconds it almost never turns up and at 7.9 seconds it almost always does.

I suspect this is just a feature to tell you what’s going on before the system shuts it down at 10 seconds run time?

Is there anything I can do other than find quicker third party APIs?

Do the services you are calling support web hooks? Using a web hook will allow you to call the first service and set the web hook to return the results when complete. The web hook would then call the second service an so on. Pushcut supports web hooks And would allow you to get around the time limits.

I use a remote proofing service which requires a link to be passed in where it can download the file that requires proofing. Sometimes this is fairly quick but depending on the loading and the complexity of the file to be proofed this can take several minutes. The server I am using has a timeout of a few seconds before it fails the call and starts another. The only way around this was to thread the call so it returned immediately, the thread then sets up the web hook and passes the file url and we wait for the web hook to be called when the proof is ready.

Thanks for the response, makes a nice change to have some help instead of a “you’re doing it wrong”!

I considered a callback but had no idea how the callback would get back to my phone. What is the URL I give it to callback? Am I thinking about this straight? I’ll be out and about, sometimes on cell service, and I can’t just port forward something to a static address on my device.

Hi Max,

The callback is handled by Pushcut for you. When you create a new notification it will automatically generate a Webhook URL which you can copy and use with one of the services when it completes its task.

This will depend on whether you are able to register a web hook with the services that you are using. I use a video generation service and these can take 15 to 20 minutes or more to complete. They have a service where you can register a web hook to be called once the video generation is complete. You can pass back a value so if you are running several videos you can work out which it is.

It’s probably not ideal going through Pushcut as each notification will appear on your screen and wait for you to interact, but unless you have access to a server of your own and can create your own endpoints then it really is a good way to get past the long delays that your APIs are creating.

Give Pushcut a go, the free version will allow you to experiment with the web hook feature and may be a good workaround.

Regards Alan

May be you could try to call scriptable using open x-callback url instead.

Scriptable would then callback your shortcut when finished. You have to perform the callback “manually” in scriptable, see this thread.