Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
When trying to loop several `webbrowser.open()` with `x-callback` to Due in, only the first call works
-
I've been trying to automate the export of Omnifocus tasks to Due, & for that I need to use Due's url scheme repeatedly in the script. You can see an example in this gist: https://gist.github.com/4b3561200491814c5538 . It looks like
webbrowser.open(url1) print 'Done 1.' webbrowser.open(url2) print 'Done 2.'
No exceptions are raised, & the output is
Done 1. Done 2.
As if all calls were made. Why does it not open the url, come back to Pythonista, & open the next one?
-
You cannot really "pause until i get a callback". You may be able to do this as a ui, by waiting for on_screen to go away, then come back.
or, make everything up to the first open one script, then everything after another script, and then whatever you want after as a third, and have the callbacks open the appropriate script. maybe pickle your state so you can pick up where you nleft off.
-
Browsing other answers, I saw people using
Scene.pause()
for this, and I coupled it withtime.sleep()
in a loop, to wait some time before repeating. It seems to work fine, but I'm not sure I usedscene
right, and maybe it's just thesleep()
that stops the script until the app regains foreground.I did think about chaining scripts though, thank you.
-
After a few more tests, I found that calling
time.sleep(n)
, wheren
is anything large enough to leave enough time to click on Ok to get to the app you want to open works. Apparently, the clock stops when the Pythonista isn't active, and so it doesn't stop waiting until we get back. -
try this. I misunderstood what you wanted to do... there is a function which checks if you are in the background. You may need to play with the first sleep to ensure you are in the bg. or have a loop that sleeps while not in background, then second that sleeps while it is..
import console,time #launch you app time.sleep(1) while console.is_in_background(): time.sleep(1) #launch your app time.sleep(1) while console.is_in_background(): time.sleep(1)