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.
Calling Python from ObjC using Xcode template?
-
Does Pythonista have any way of passing down data from ObjC to Python, like say the launchOptions arguments that can be passed in on launch? Particularly I would like to pass the value of UIApplicationLaunchOptionsURLKey down into the script somehow.
-
Shamelessly copied straight out of Pythonista:
Command-line Arguments
When using theaction=run
parameter (see above), you can pass command-line arguments to the script in two ways:Method 1: One args parameter
Example:
pythonista://MyScript?action=run&args=foo%20bar
When you pass a single string with the args URL parameter, the string is split by spaces (the space is encoded as %20 here) and sys.argv would be
[<script_path>, 'foo', 'bar']
in this example.If you want to pass arguments that contain spaces, you have to enclose them in double quotes (as you would in a classic shell).
This is basically the same as running a script by long-pressing the run button.
Method 2: Multiple argv parameters
Example:
pythonista://MyScript?action=run&argv=foo&argv=bar
Using multiple arguments that are all named argv, you don’t have to worry about quoting arguments that contain spaces. Each of the parameters corresponds to one element in sys.argv.
If the URL contains at least one argv parameter, args is ignored.
Maybe you can use this?
-
Thanks, but I don't actually want to send the args to the Pythonista app, I want them to come to my own app, which is built using Pythonista. This is for "open in" functionality in my app.