From Shortcuts to Pythonista to Shortcuts
-
I’m beginning to learn Python and Pythonista. As English is not my native language (I’m French) and all documentations and examples are all in English, it’s sometime difficult ;-)
The forum is an extraordinary place to get infos even if the level is very hight for a beginner ;-)
I thank you all.
With the small exercices that I try to resolve, I progress slowly.
But I get stuck for few days with a small problem. The thing I want to do looks simple (I've found an example on the forum but it's to difficult for me) :- I want to init to random numbers in Shortcuts,
- then add them in Pythonista,
- then get and show the result in Shortcuts.
Points 1 and 2 are done : from Shortcuts, I send:
pythonista://somme.py?action=run&argv=var1&argv=var2
var1 and var2 are my random numbers and somme.py is my Pythonista script:
import sys, webbrowser n1, n2 = int(sys.argv[1]), int(sys.argv[2]) n3 = n1 + n2 url = "shortcuts://" webbrowser.open(url)
I’ve found a solution to transfer the result to Shortcuts with the clipboard but it seems possible to do it with x-callback but I can’t find how :-(( I've tried many options in my url in Pythonista and the Open X-Callback URL in Shortcuts but it's always bad.
I need help and I know that I can count on you ;-)
-
@Enez-Houad Strange, that works for me. I have the new beta installed, and you?
-
@Enez-Houad You can see here an mp4 of recording my screen during shortcut-Pythonista-shortcut
-
@cvp I use the last beta of Pythonista too !
And here is a mp4 recording of my screen.
https://drive.google.com/open?id=1-b5L99gCvsmfsZPQOGtUuUvJrDD6bbBW
Strange !
-
@Enez-Houad Did you try to remove both apps from memory?
-
@Enez-Houad Please try with two "-" between run and shortcut, for me it makes a difference but don't ask me why
url = "shortcuts://x-callback-url/run--shortcut?name=[Shortcut_Name]&input=clipboard
On a zoom of your movie, it seems to be only one
-
@cvp It's ok with two :-)) Thanks for your patience !
-
@Enez-Houad 😅 This double - is not documented....
-
Shortcuts’
Open X-Callback URL
allows for setting custom callback keys. By settingSuccess Key
toargv
the success is appended to the call to Pythonista as the last argument. Unfortunately only one of the keys can be set toargv
as only the last one will be appended.Here’s an example:
from datetime import datetime import json from urllib.parse import quote_plus .... x_success = sys.argv[-1] # shortcuts-production://x-callback-url/ic-success/<UUID> x_cancel = x_success.replace('ic-success', 'ic-cancel') x_error = x_success.replace('ic-success', 'ic-error') x_success += '?x-source=Pythonista3' x_success += '&result=' + quote_plus({....}) x_success += '&datetime=' + quote_plus(str(datetime.today())) webbrowser.open(x_success)
Hope this is helpful to someone.
Cheers,
-
This worked for me Using iOS Shortcuts App and Pythonista