Saving clipboard image to specific file
Hey I feel like this should be really simple, I just want a small script that runs from the share sheet that takes an image and saves it to a specific file. My issue is I can’t seem to get the path part to work. how can I get a specific files path?
ccc last edited by
Maybe provide the code that you have so far? An appex script that finds an image on the clipboard and attempts to do an Image.save() on it.
JonB last edited by
By "writing to a specific file", did you mean that you have hardcoded a filename that you want to write to?
Are you trying to write to a specific path in your "This iPad" folder? Or somewhere else?
Or by "specific file", do you mean you are trying to edit the file that was provided to you on the sharesheet, and save modifications to that image back to the original?
In the later case, generally you cannot edit the original files that are shared to you. There are ways to save images back to your photo albums, but you have to use the photos module instead of "writing to a file".
So, can you clarify your desire -- write to a local file (only accessible to pythonista, or possibly iCloud external folder)? Or write back to photos so you can see the modified file by other apps?
Hey thanks for the replies, I would share my code but it’s super basic, just gets the clipboard pil image and then saves it to a location using a path. So I would like to understand how to save it to different locations. Ideally as a starting point somewhere in my iCloud but somewhere on the my iPad part of pythonista would be fine, I just don’t know how to set up a functioning path to any of these places.
Also in my original post I said save to file I actually meant folder, oops
cvp last edited by
JonB last edited by
import sys,os print(os.path.abspath('.'))
That's your current path. You can usually use relative paths to the main script that you ran -- e.g
open('test.jpg')will open the file in the same folder as your script.
In some cases, if you have a module in site-packages, a way to get back to the main script in pythonista is
import sys,os print(os.path.abspath(sys.path))
due to the way that pythonista adds the script that you pressed the play button on to the top of the sys.path.
If you run that little script from a script located in folder inside iCloud folder, it will print out the absolute path, and you can use that in your scripts to write to iCloud. Note, you usually cannot write directly to the iCloud folder itself, you need a subfolder.