Forum Archive

Save Script via Open In directly to Pythonista

mncfre

This is a python script that work in conjunction with a workflow (you need Workflow for ios) to enable open scripts .py (Only .py for now) and save it directly on Pythonista. It's useful when someone send you a .py via email or if you have scripts saved in Downloads app or GoodReader App, and you want to save the .py directly on pythonista, just select the file, hit "Open In.." then "Run Workflow" then select "Save Python" and that's all. If the script that you're trying to save already exist, it rename the new one with a consecutive.

The workflow link is: https://workflow.is/workflows/8cdee57f79664205a6a565c9cbdb3d48

The repo link of the script is:
https://github.com/mncfre/Save-Script

Please feel free to contribute to get better this code.

Tizzy

Nice! I tossed around the idea that this might be possible at the back of my mind while messing around with workflow. Good work!

mncfre

Thanks a lot @Tizzy, now I want to add the open in .pyui files too.

techteej

@mncfre Just tried this an got a list index out of range error.

ccc

TJ, were you in Downloads.app and do an Open in... Workflow.app as is described in the first post in this thread?

If you just run this script in Pythonista with no argv parameters, you will get a list index out of range error.

mncfre

Still trying to save the .pyui but workflow seems to manage the .pyui as binary, I can't use the clipboard for now and I don't like the dropbox solution, if some of you have some idea please tell us here.

JonB

Just rename the pyui as text or py. It is a pure textfile.

mncfre

Thats a good idea but I'm looking for a more automatic solution that avoid changing the extension manually, I'm gonna try something like that but in workflow

mncfre

Script updated to ask file extension, using the @JonB suggestion, so if you have a .pyui change its extension to .py then “open in” then in pythonista select .pyui extension, it’s not perfect but it’s all I have now.

techteej

@ccc I was in Dropbox. Wishful thinking :[

mncfre

@techteej that's because when you "open in" from Dropbox it actually don't open the file, it generate a link of the file, in theory I can do a workflow especially for Dropbox of you need it

smath

If using this with the dropbox app, you just need to add a step. Tap share>open in>run workflow instead of going directly to run workflow.

I have updated both the script and the workflow. The changes are as follows:

Workflow: I kept getting the wrong file name, so I updated the workflow to pass the right file name to pythonista. I also made the Documents folder the default with the option to add to the path. I don't know if the way I set up the default folder will be the same on all devices or not.

Script: I changed the system argument index, which was giving me an out of range error and made it so that instead of printing the path, the file is opened once it is created. Finally, I made an option for other file types where you can type in the file extension.

smath

Workflow: I kept getting the wrong file name, so I updated the workflow to pass the right file name to pythonista. I also made the Documents folder the default with the option to add to the path. I don't know if the way I set up the default folder will be the same on all devices or not.

Script: I changed the system argument index, which was giving me an out of range error and made it so that instead of printing the path, the file is opened once it is created. Finally, I made an option for other file types where you can type in the file extension. Script

jaredbidlow

I get an error running this script
No such file directory

Olaf

@jaredbidlow, Pythonista 2.0 provides appex, so you don't need Workflow and the clipboard anymore to Open in Pythonista. See e.g. https://forum.omz-software.com/topic/2494/appex-getfromurl-to-share-from-other-apps-to-pythonista for an alternative

Webmaster4o

@jaredbidlow This is almost completely useless now. There's a much simpler way to do this now that doesn't require Workflow.

[deleted]

Or see Save Attachment

ScottSmith

I've updated this script, as well as the associated Workflow, to make it more reliable and work with Pythonista 2, as well as allow for replacing the file extension on save. https://gist.github.com/ScottSmith95/2f9b249f9e6e0e9fc6ef