run_script.py (for Pythonista Tools & iOS Shortcuts) #136
RichardPotthoff
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Normally Pythonista only offers script from "This iPad" in a dropdown menu, but the Python script you want to run may be in the "Files/Python 3/SomeProject" directory.
My solution for this is: Just pass the full path to the script as parameter to a script that is located in "This iPad", and which therefore can be selected from the dropdown list. Here is the script
run_script.py:Here is how I use it as Pythonista Tool (the wrench icon at the top right in Pythonista):
Select "Edit", "+" (to add a new shortcut), and fill out the form:
Please note that I have added two arguments: The script's path, and a command line argument that is passed to the script. Pythonista>Tool will add an additional argument: The path to the Python Script that is being edited. So you have to be carefull and keep this in mind.
In this example the Python script is located on a SMB share on a raspberry pi on my local network. To make this work, Pythonista needs permissions. To allow Pythonista access to the SMB share, you have to add a bookmark in Pythonista by selecting "EXTERNAL FILES > Open...>Folder...". Then you have to navigate to the folder you want bookmarked(and that contains the script you want to run) and click "Open" to bookmark it. It is sufficient to bookmark the top level directory (I think) in the example that is the "oRJK7QPythonista" directory. The first 6 letters were added by the SMB system. They may change , in which case you have to set a new bookmark, but it has not happened to me yet.
An easy way to get the full pathname is to use this script (
get_path.py):Save it to the directory you want to know the path of, and run it in Pythonista. The path will be copied to the clipboard.
The same method can also be used for iOS "Shortcuts" using "Run Pythonista Script" in "Shortcuts".
All reactions