omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Passing An Image Back To Workflow

    Pythonista
    7
    25
    22003
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • omz
      omz last edited by

      @MartinPacker I haven't really tried this yet, but an easy way might be to use the clipboard.

      1 Reply Last reply Reply Quote 0
      • abcabc
        abcabc last edited by

        I tried the following workflow and it seems to work fine.

        1. Select photos
        2. share (run pythonista appex script "convert_to_gray_image.py" given below)
        3. Get Clipboard
        4. Save to photo album

        The script "convert_to_gray_image.py" is given below.

        from PIL import Image, ImageOps
        import appex
        import ui, clipboard
        
        def main():
            if not appex.is_running_extension():
                print('This script is intended to be run from the sharing extension.')
                return
            img = appex.get_image()
            if not img:
                print('No input image')
                return
            if not img.mode.startswith('RGB'):
                img = img.convert('RGB')
            gray_img = ImageOps.grayscale(img)
            clipboard.set_image(gray_img)
        
        if __name__ == '__main__':
            main()
        
        
        1 Reply Last reply Reply Quote 0
        • cvp
          cvp last edited by cvp

          You should be able to add actions in your workflow to:

          • action: select photo, to avoid Photos app
          • action: copy your photo to the clipboard
          • action: run your Pythonista script, to avoid manually sharing the photo to your script!
            • get clipboard
            • convert in gray
            • copy to clipboard
            • start Workflow
          • action: get clipboard
          • action: save
          1 Reply Last reply Reply Quote 0
          • MartinPacker
            MartinPacker last edited by

            Thanks to all.

            Workflow can have an image passed in to a "stage" in its pipeline. And I think it can have a stage output one.

            While OK on the clipboard or persistent file front I wondered if the Pythonista stage could ingest and emit images directly.

            1 Reply Last reply Reply Quote 0
            • abcabc
              abcabc last edited by abcabc

              Here is the modified script that uses action script instead of share script. ( @cvp What is "start workflow" step in "pythonista script"?
              Do I have to add " webbrowser.open("workflow://") at the end?)

              from PIL import Image, ImageOps
              import ui, clipboard
              import webbrowser
              
              def main():
                  img = clipboard.get_image()
                  if not img:
                      print('No input image')
                      return
                  if not img.mode.startswith('RGB'):
                      img = img.convert('RGB')
                  gray_img = ImageOps.grayscale(img)
                  clipboard.set_image(gray_img)
              
              main()
              webbrowser.open('workflow://')
              
              
              1 Reply Last reply Reply Quote 0
              • cvp
                cvp last edited by cvp

                url_scheme = 'workflow://x-callback-url/run-workflow?name=your_file&input=clipboard&x-success=pythonista://'
                if appex.is_running_extension():	
                	app = UIApplication.sharedApplication()
                	app.openURL_(nsurl(url_scheme))
                else:
                	webbrowser.open(url_scheme)	
                # assume your Workflow writes xxx in the clipboard to warn it is finished
                text = clipboard.get()
                while text != 'xxx':
                	text = clipboard.get()
                	time.sleep(0.3)
                
                1 Reply Last reply Reply Quote 0
                • abcabc
                  abcabc last edited by abcabc

                  @cvp Thanks. I do not use (or the need to create) any complicated workflows and I feel that "webbrowser.open('workflow://')" is good enough to return back to workflow app.

                  @MartinPacker editorial could do that (i.e. ingest and emit images directly). Workflow app may not add this facility in future but omz can make editorial workflow as easy as workflow app.

                  1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp last edited by

                    If I correctly understood your request, you don't need Workflow because your Pythonista script could perform it-self all your "actions", like

                    • select photos
                    • convert them
                    • save them to an album
                    1 Reply Last reply Reply Quote 0
                    • abcabc
                      abcabc last edited by

                      1. My example is for illustration purpose only and I do not require that workflow. My sentiments are similar to the ones expressed in the following blog.
                        https://spin.atomicobject.com/2016/01/16/ios-workflow-frustrations/

                      2. But the template could be useful in doing something very fast with little code, may be at some time later. Your comments are very helpful in building the template.I have also looked at the workflow site
                        https://workflow.is/developer and the reddit site https://www.reddit.com/r/workflow
                        I do not want to investigate much into this now and I am ok with current action script template.

                      Once again I would like to thank you for your helpful comments and I will look at your"x-callback-url" some time later.

                      1 Reply Last reply Reply Quote 0
                      • cvp
                        cvp last edited by

                        Before I know Pythonista, I wrote a lot of Workflows, but since I use Pythonista, I've rewritten all in Python, with only one exception for Workflows saving or getting a file to/from ICloud Drive because Pythonista does not provide this functionality.

                        1 Reply Last reply Reply Quote 0
                        • ccc
                          ccc last edited by ccc

                          Would it be possible to interop with iCloud Drive using objc_utils? Or with something like https://pypi.python.org/pypi/pyicloud

                          1 Reply Last reply Reply Quote 0
                          • cvp
                            cvp last edited by

                            I don't think so, I had already seen this import but it does not cover the iCloud Drive storage, only ICloud services.

                            1 Reply Last reply Reply Quote 0
                            • MartinPacker
                              MartinPacker last edited by

                              To reveal a little more of the picture...

                              ... My idea was to create a graphing Pythonista capability so Workflow might pass a CSV (file) into Pythonista and then do something with the graph (image) returned.

                              In essence I wanted to add graphing to Workflow. I would expect Pythonista would be a good way to do it.

                              Would Editorial do this better than Pythonista?

                              Phuket2 1 Reply Last reply Reply Quote 0
                              • ccc
                                ccc last edited by

                                @cvp Please check the File Storage (Ubiquity) section of the page:

                                You can access documents stored in your iCloud account by using the files property’s dir method

                                cvp 1 Reply Last reply Reply Quote 0
                                • Phuket2
                                  Phuket2 @MartinPacker last edited by

                                  @MartinPacker , I am not really sure about Editorial vrs Pythonista for the graphing, they could be equivalent. But my guess would be that Pythonista would be the superset of functionality.
                                  But just really wanted to mention the 'Pie Chart Demo.py' in the Examples/Plotting dir in Pythonista. Great demo how to easily create a pie chart with some nice features. It's so easy to understand. Then I am pretty sure if you use a ui.ImageContext to draw into you could return that image for the clipboard. Possibly the matplotlib gives a more direct way. Just interesting

                                  1 Reply Last reply Reply Quote 1
                                  • cvp
                                    cvp @ccc last edited by cvp

                                    @ccc
                                    Hi
                                    I had checked this page but they only support iCloud file storage, that will say Apple apps storage, like Notes, but not iCloud Drive storage of all other apps, what does Workflow app.
                                    In Workflow, you can save a file to the ICloud Drive of another app, like Documents, FileBrowser, Pages, Numbers etc...

                                    1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp last edited by

                                      @ccc
                                      It's exactly like you can manually do in Pythonista by

                                      • edit
                                      • select a file
                                      • share
                                      • add to ICloud Drive

                                      But automatically

                                      1 Reply Last reply Reply Quote 0
                                      • MartinPacker
                                        MartinPacker last edited by

                                        All this talk about iCloud illustrates one of the reasons why I'm not looking for a "write to file" solution.

                                        Clipboard would be fine, though "trashing" the clipboard should only be done if necessary. It seems that it is.

                                        1 Reply Last reply Reply Quote 0
                                        • MartinPacker
                                          MartinPacker last edited by

                                          Something for y'all to pick the bits out of...

                                          A reply from @WorkflowHQ on Twitter contained the following...

                                          "Also regarding sending images, Workflow can decode base64 encoded images."

                                          Does this help us here? Can we encode images base64?

                                          1 Reply Last reply Reply Quote 0
                                          • omz
                                            omz last edited by

                                            @MartinPacker Encoding images as base64 should be fairly straightforward in Python. Do you have any more details?

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors