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.
Script to import any file in Pythonista from any app
-
Thanks a lot for sharing this!
I'm still very new to Pythonista and importing a lot of scripts and ui files from the web to learn - your script is a life saver ! -
@chebfarid
If you want to save it in a folder you choose:import File_Picker # from @omz dest_dir = File_Picker.file_picker_dialog('Select the folder where you want to save the file', multiple=False, select_dirs=True, file_pattern=r'^.*\.py$')
-
@cvp Thanks a lot, I'll give it a try tonight.
-
Sorry if this should be obvious to everyone, but how to save this script as an extension? I see how to create text, image, and URL extensions but do I have to know in advance the type of file to be shared/saved?
-
@ihf You can use any script in the app extension. Either edit the shortcuts in the settings (within the main app) or use the Edit button in the extension itself.
The text/image/url extensions you're referring to are just templates for scripts that interact with data passed into the extension. You don't have to use them.
-
If I simply add the script send then from the IOS sharing menu select it(within Photos),I get:
Input path: None
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/AA838D46-5C81-42AA-9301-F57202B8AD48/Pythonista3/Documents/.Extension/SaveFile.py", line 57, in <module>
main()
File "/private/var/mobile/Containers/Shared/AppGroup/AA838D46-5C81-42AA-9301-F57202B8AD48/Pythonista3/Documents/.Extension/SaveFile.py", line 47, in main
filename=os.path.join(dest_path, os.path.basename(file))
File "/var/containers/Bundle/Application/E7467484-E2A2-4AA3-B7E4-6621D1F13B23/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/posixpath.py", line 141, in basename
i = p.rfind(sep) + 1
AttributeError: 'NoneType' object has no attribute 'rfind' -
Still don't see where my error is. Perhaps someone can enlighten me?
-
Further experimentation reveals that if you try to save a .jpg file (from Photos) you get the above reported error. PDFs (for one) work properly. It would be nice if this script could save any shared file.
-
Modifying the script to work in Photos should be relatively easy. If
appex.get_file_path()
returnsNone
, you could checkappex.get_image()
, and save that. Roughly like this:# ... file = appex.get_file_path() img = appex.get_image() if file is not None: filename=os.path.join(dest_path, os.path.basename(file)) filename=getuniquename(filename, '') print('Input path: %s' % file) shutil.copy(file, filename) elif img is not None: print('Saving image') filename=os.path.join(dest_path, 'imported_image.jpg') filename = getuniquename(filename, '') img.save(filename) # ...
-
the most easiest method is to change file extension. e.g. change filename.py to filename.txt. ]
rename it back after receiving.currently I found iOS cannot send some file types to Pythonista , e.g. *.py *.pem *.cer,
but I can send them after rename change file extension.rename is easy. easy than that much code
-
Hi, thanks for sharing. What's the best way to import your above coding into Pythonista? Have tried a couple fo ways like copying them into a txt or py file, and change the coding to ANSI or UTF-8, but once imported into Pythonista they all show invalid characters.
Thanks!
-
@Ericlin I don't understand your problem. Normally, you should
- select the script lines in the forum
- copy
- launch Pythonista
- create a new script via the + button at right in the top bar menu
- put your cursor in the first line
- paste
That's all