Hi - I’m trying to execute two callbacks to an app (Ulysses) in a Scriptable script. The first callback creates a new sheet in Ulysses and using the sheetID from that callback, I then want to insert more information into that sheet via another callback that uses sheetID to reference the sheet.
Everything works great when I execute the script from Scriptable itself. However, when I run it via the share sheet, it executes the first callback and then returns to Scriptable, and never executes the second callback. Is this expected behavior? Any way to execute multiple callbacks in the same script when invoked from a share sheet? Thanks!
Since you can’t return to a share sheet with a URL scheme, you could try running everything from inside the app. To do this simply toggle Always Run in App on in the script settings.
Looks like Scriptable doesn’t clear its input data it receives like with opening Scriptable from a notification. In the latter case there is the Notification.resetCurrent() function to clear this input, but apparently there is nothing for a callback URL and it only gets cleared by a force close from the app switcher.
@simonbs could you please implement a clear function for this use case? Or is it a bug?
The behavior described in this thread sounds like a bug. Thanks for reporting it. I’ve added a todo to look into it. I hope I can squeeze it into a build soon.
@baseliners I’m looking into this issue and trying to reproduce it but after re-reading this post I’m not sure about your setup. Can you share an example script with me?
Hi @simonbs - here’s the relevant code that I’m using:
// invoke Ulysses, create a new sheet, and get the ID of the sheet
let callback = new CallbackURL("ulysses://x-callback-url/new-sheet")
callback.addParameter("text", title)
callback.addParameter("index", "0")
var result = await callback.open()
sheet_id = result.targetId
// invoke Ulysses, add keywords to the sheet created
let callback2 = new CallbackURL("ulysses://x-callback-url/attach-keywords")
callback2.addParameter("id", sheet_id)
callback2.addParameter("keywords", keywords)
var result2 = await callback2.open()
// invoke Ulysses and add images (received as input from share sheet) to the sheet created in Ulysses
for (i = 0; i < args.images.length; i++) {
data = Data.fromJPEG(args.images[i])
let image_data = data.toBase64String()
let callback2 = new CallbackURL("ulysses://x-callback-url/attach-image")
callback2.addParameter("id", sheet_id)
callback2.addParameter("format", "jpg")
callback2.addParameter("image", image_data)
var result2 = await callback2.open()
}
That sounds great, thank you! One update - the script that was running well except for the issue in this thread, has now stopped working and gives me the same error even on the first execution (i.e. starting from all apps being closed out from the app switcher). The two main changes on my end were 1) upgrading to iPadOS 14.1, and 2) updating Scriptable on 10/18. Not sure if the fix works in 14.1 as well. Look forward to trying it out!
Hi @simonbs - I installed the latest Scriptable update (and also iPadOS 14.2). I ran the workflow around 12 times with no issues and thought the problem was fixed. However, we’re now back to almost the same behavior.
It runs and after creating a sheet in Ulysses, returns to Scriptable and has the spinning wheel and stays there (which is slightly different from the earlier behavior where I’d get the popup with the callback exception error right away). When I go to close out Scriptable, I get the callback exception popup like before. After I closed it via the app switcher, it ran fine once, but on the next execution, I ran into the same issue. And then, even after closing out completely, it did not execute. I tried a couple more times (closing out via the app switcher and re-executing) and it did not execute. But it again started working (and worked fine a couple successive times) after another close out. So, there still seems to be some issue since it’s not consistently executing.
Hi @simonbs - wanted to follow up on this. I’m afraid the issue still persists, and I usually have to cold restart the iPad before I can get it to work again (i.e. finish w/o hanging in the middle w/ an exception). Would be awesome if there was a way to fix the issue. Thanks!