Thanks for the suggestions @mikael. I actually started playing around with
get_image_databut was finding inconsistent data values there. In particular,
get_image_dataoften had a Boolean as value rather than actual data, whereas
PIL.PngImagePlugin.PngImageFile. This seems different than the documented behavior from the `appear documentation, but I can’t tell if that is a Pythonista issue or whether Pythonista just passes through the data from the calling app, in which case that is where the issue might lie.
The source of the image (i.e. the app from which I’m triggering the share sheet) is CalmApp, in case that matters.
I'm trying to automate some data collection across various app-enabled activities (e.g. meditation) to a central Google Sheets spreadsheet, using Dropbox to collect any associated images. This is implemented via a Pythonista app triggered via the share sheet. For example, after a meditation, I share the final summary view with the script, and it logs some details about the meditation to Google Forms (which ends up in Google Sheets) and saves any image passed to the share sheet to Dropbox. A URL to the uploaded image is included in the Google Forms submission.
My challenge is that the Dropbox image upload is slow enough to really disrupt my flow, so I'm trying see if there is an obvious way to speed it up. In particular, it looks like I have to explicitly write out the image to a BytesIO stream, even if it is already in the desired format (PNG) -- see uploader code below. Is there a faster way to do this? For example, is there a way to perform these operations in parallel / async i.e. grab the shared link while the image uploads in the background?
Thanks in advance!
def upload_image_to_dropbox(image, pathname_in_dropbox): with io.BytesIO() as output: # this seems necessary even if image.format is already "PNG" image.save(output, format="PNG") contents = output.getvalue() dbfile = dbx.files_upload(contents, pathname_in_dropbox, dropbox.files.WriteMode.add, mute=True) # takes a long time dbfile_url = dbx.sharing_create_shared_link(pathname_in_dropbox, short_url=False, pending_upload=None) link_to_image = dbfile_url.url.replace("?dl=0","?raw=1") return link_to_image
Is there any way for a Pythonista script triggered from the Share Sheet to know what app the user was in? I have a single script that I want to trigger from 4-5 different apps. Right now I have created separate Share Sheet entries/icons for each use case, triggering the same script but with a different (manually configured) argv parameter. It would be great if the script could just figure this out on its own but I can't find it in the libraries.
Any suggestions or workarounds?
Thanks @7upser -- very helpful. I've been able to reproduce your example with the Pythonista Url scheme and the script is now found and launched correctly. However it jumps into/drops me into Pythonista proper. Is there a way to avoid that (i.e. just run the whole script in the background)?
I’m trying to call Pythonista for the first time from a Shortcuts workflow. I understand that I should be able to call the Python code, passing values into argv somehow, but that there isn’t a direct way to return values unless you use a workaround (e.g. store the output value in the clipboard from Python, then retrieve the clipboard when the shortcut picks up again).
I’m having trouble getting the Shortcut to actually find my Pythonista script. I’ve tried saving it both on iCloud and “on my iPad”.
I’m triggering Pythonista by adding the “Run Script” step to my workflow, and then providing the name of the script. I’ve trying various syntaxes:
The last one is the one that Pythonista seems to recommend, in that it is auto-generated when I select Wrench > Shortcuts... > Pythonista URL > Copy URL.
In all cases, the call fails a "The file [filename] cannot be found" dialog box in Pythonista.
Can someone confirm that I should, in fact, be using the "Run Script" command in Shortcuts for this, as well as the syntax to use and location the script needs to be at in order to be found?
Thanks in advance!
Hi all —
I’m just learning Pythonista and am trying to create a share sheet shortcut that will log data to a Google spreadsheet via a form. Some of the actions I’d like to save come from apps that include an image when the share sheet is triggered, and I’m looking for examples or recommended idioms for how to do this via Pythonista.
In particular, if I understand the control flow correctly, for this image to make its way off my iPad I have to save it to somewhere Internet-accessible (for example Imgur or Dropbox) and then retrieve a URL that points to the (now-Internet-accessible) image and passing that URL on for further processing. For example, if that URL gets pushed to Google Sheets, then Google will be able to retrieve the image and display it inline in the spreadsheet.
Are there examples or best practices of how to do this that anyone could point me to? For example:
- Retrieve the PIL image data from the share sheet data
- Save that image to [Dropbox/file share service X]
- Retrieve a URL pointing to that saved image
- Do further processing with it
Thanks in advance for any pointers or suggestions,
I will need to save