Correct way to call Pythonista script from within a Shortcuts workflow?
-
Hi —
I’m trying to call Pythonista for the first time from a Shortcuts workflow. I understand that I should be able to call the Python code, passing values into argv somehow, but that there isn’t a direct way to return values unless you use a workaround (e.g. store the output value in the clipboard from Python, then retrieve the clipboard when the shortcut picks up again).
I’m having trouble getting the Shortcut to actually find my Pythonista script. I’ve tried saving it both on iCloud and “on my iPad”.
I’m triggering Pythonista by adding the “Run Script” step to my workflow, and then providing the name of the script. I’ve trying various syntaxes:
- MyScript.py
- MyScript
- pythonista3://getPTEimg.py
- pythonista3://iCloud/getPTEimg.py
- pythonista3://iCloud/getPTEimg.py?action=run&root=iCloud
- pythonista3://iCloud/getPTEimg.py?action=run
The last one is the one that Pythonista seems to recommend, in that it is auto-generated when I select Wrench > Shortcuts... > Pythonista URL > Copy URL.
In all cases, the call fails a "The file [filename] cannot be found" dialog box in Pythonista.
Can someone confirm that I should, in fact, be using the "Run Script" command in Shortcuts for this, as well as the syntax to use and location the script needs to be at in order to be found?
Thanks in advance!
Ramon
-
This works for me, the script is in This iPad/dir:
The iCloud Path should be:
/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documentsbut i dont use parameter
Edit:
Did a test for parameter with url scheme:
see here: Pythonista Url schemeworks too
-
Thanks @7upser -- very helpful. I've been able to reproduce your example with the Pythonista Url scheme and the script is now found and launched correctly. However it jumps into/drops me into Pythonista proper. Is there a way to avoid that (i.e. just run the whole script in the background)?
-
@felciano said:
just run the whole script in the background
I don't think that Pythonista can run in the background.
Apple only authorizes that for music or Bluetooth apps.
-
You can Start a Shortcut with Pythonista:
import webbrowser vUrl = 'shortcuts://run-shortcut?name=testStartWithUrlScheme&input=10' webbrowser.get('safari').open(vUrl)
Maybe you can split your Shortcut into 2 different Shortcuts.
This should work, if you use Url Scheme on both sides.
(it's not really in the Bachground, as cvp mentioned)