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.
From Shortcuts to Pythonista to Shortcuts
-
@Enez-Houad When your Shortcut exécutés a Pythonista script, it waits for its return
Example of Pythonista backimport sys, webbrowser,clipboard n1, n2 = int(sys.argv[1]), int(sys.argv[2]) n3 = n1 + n2 print(n1,n2,n3) clipboard.set(str(n3)) url = "shortcuts://x-callback-url/run--shortcut?name=[Shortcut_Name]&input=clipboard" webbrowser.open(url)
-
Thanks for your answers. You confirm that my solution with the clipboard was good :-)
The problem I have is that I wanted to understand how to use the open x-backcall from Shortcuts and the documentation doesn’t help (don’t forget that I’m a beginner ;-)
I think that I could use :url = "shortcuts://x-callback-url/run--shortcut?name=[Shortcut_Name]&input=text&text=[n3]"
But when I use this script there’s an infinite loop because the shortcut is relaunched at its beginning...
-
@Enez-Houad In your Shortcut, do you call Pythonista via url or do you with the "Execute Pythonista script"command, because my example above works for me
-
@Enez-Houad Try this shortcut with my little script above
-
@cvp I've tried your shortcut with this script :
import sys, webbrowser,clipboardn1, n2 = int(sys.argv[1]), int(sys.argv[2]) n3 = n1 + n2 clipboard.set(str(n3)) url = "shortcuts://x-callback-url/run-shortcut?name=Shortcut_Name&input=clipboard" webbrowser.open(url)
I've got an infinite loop.
-
@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