omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    webbrowser x-callback
    2
    5
    4415
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ejetzer
      ejetzer last edited by ejetzer

      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?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 1
        • ejetzer
          ejetzer last edited by

          Browsing other answers, I saw people using Scene.pause() for this, and I coupled it with time.sleep() in a loop, to wait some time before repeating. It seems to work fine, but I'm not sure I used scene right, and maybe it's just the sleep() that stops the script until the app regains foreground.

          I did think about chaining scripts though, thank you.

          1 Reply Last reply Reply Quote 0
          • ejetzer
            ejetzer last edited by

            After a few more tests, I found that calling time.sleep(n), where n 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.

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by JonB

              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)
              
              1 Reply Last reply Reply Quote 3
              • First post
                Last post
              Powered by NodeBB Forums | Contributors