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.
Pythonista to call workflow and return
-
I thought this would be simple but app integration seems never to be simple.
I want to my script to invoke workflow, run a workflow action, and return to pythonista and have the script continue. Workflow will pass nothing back to the script so that complexity isn't relevant.
code
webbrowser.open("workflow://x-callback-url/run-workflow?name={{Play Specific}}&success={{pythonista://ferny_launch}}")
I don't really need to wait for success. The workflow script runs Apple Music app. I certainly don't want to wait for the song to play. I realize that pythonista doesn't support x-callback-url, but it's workflow that needs to callback, not pythonista. I realize that python won't like double curly braces, but python should never see them. They are part of the quoted url text string sent to workflow so that I don't need to put in the literal characters for spaces and punctuation.
Do I really need to even have the success clause? It seems like if IOS returns back to pythonista, the script should still be running.
This is the only line in the button action function. So, the script should be happily waiting in the event loop for the next button tap.
I must be missing something very obvious because it doesn't seem hard.
Thanks,
Lewis -
OK, well one obvious problem is that I got workflow mixed up with launch center pro. The {{ syntax is their way of encoding valid url strings. NOT workflow.
OK, so more progress...
-
alternative approach is to use requests.get() something like
try: from urllib.parse import quote_plus, urlencode # Python 3 except ImportError: from urllib import quote_plus, urlencode # Python 2 import requests def url_finish(*args, **kwargs): """completes the right side of a url. URLs for REST APIs are composed of three parts: 1. Base URL: workflow://x-callback-url 2. Path Parameters (args) separated by /'s 3. Query Parameters (kwargs) started with a ? and then urlencoded args are a tuple of unnamed values that go on the left of the ? kwargs are a dict of named values that are urlencoded to right of ?""" s = '' if args: s = '/' + quote_plus('/'.join(str(arg) for arg in args), safe='/') if kwargs: s += '?' + urlencode(kwargs) return s base_url = 'workflow://x-callback-url' url = base_url + url_finish('run-workflow', name='Play Specific', success='pythonista://ferny_launch') print(url) requests.get(url)
-
Well, lots of dumb mistakes as I suspected.
Has to be x-action, not action.
So, for completeness this is what works:
webbrowser.open("workflow://x-callback-url/run-workflow?name=Play%20Specific&x-success=pythonista:")
And this returns right away because this workflow launches music without waiting for a return. So, from workflow's standpoint the workflow finishes immediately.
Closed and Solved