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.


    Is it possible to read a file, say txt file, from other app?

    Pythonista
    pythonista file importing dropbox
    7
    12
    11869
    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.
    • dgelessus
      dgelessus last edited by

      Yes, GoodReader opens a share sheet when you tap "Open in ...".

      @JonB, if you want to copy a file, use shutil.copy. Much shorter than manually opening the two files (and you don't risk any accidental bytes-to-text conversions for binary files).

      1 Reply Last reply Reply Quote 2
      • Webmaster4o
        Webmaster4o last edited by

        The reason you cannot read from another app (without jailbreak) is that all apps in iOS are sandboxed, and cannot access much content outside of their own app bundle.

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

          In this case, appex delivers neither a file handle nor a file name but instead delivers the contents of the file as a str.

          https://github.com/cclauss/Ten-lines-or-less/blob/master/appex_local_copy.py should give you a local copy.

          1 Reply Last reply Reply Quote 1
          • dgelessus
            dgelessus last edited by dgelessus

            @ccc Really?

            >>> import appex
            >>> appex.get_attachments()
            [u"/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf", u"/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf"]
            

            (Don't ask me why the same path is listed twice though.)

            1 Reply Last reply Reply Quote 1
            • JonB
              JonB last edited by

              i suspect for textfiles, goodreader returns the path as one attachment, and the url as another. I noticed this when safari does a Save As (in my case, i was saving a png, and i got the file contents on one, and file path in another. My script just uses get url, and urllib.urlretrieve, which seems to work both for private pathnames and internet urls. .

              1 Reply Last reply Reply Quote 1
              • dgelessus
                dgelessus last edited by

                This makes a little more sense... but only a little.

                >>> import appex
                >>> import json
                >>> print(json.dumps(appex.get_input(), indent=4))
                [
                    {
                        "attachments": [
                            {
                                "com.adobe.pdf": "/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf", 
                                "public.file-url": "/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf"
                            }
                        ]
                    }
                ]
                
                1 Reply Last reply Reply Quote 1
                • ccc
                  ccc last edited by ccc

                  My mistake... I was reading a file shared from Editor, not from GoodReader.

                  import appex, shutil
                  
                  if appex.is_running_extension():
                      file_path = appex.get_file_path()
                      if file_path:
                          shutil.copy(file_path, '.')
                  
                  1 Reply Last reply Reply Quote 1
                  • gregr
                    gregr last edited by

                    To the original question - it would be cool if there was a way to open a file from a document provider in another app. Sort of as described in this blog post, where 1Writer is using the document provider from Working Copy to open a file in-place (i.e. without making a new copy):

                    http://www.rassoc.com/gregr/weblog/2016/01/15/using-working-copy-with-1writer-on-ipad-pro/

                    1 Reply Last reply Reply Quote 1
                    • iBayern
                      iBayern last edited by

                      Thank you very much every body fir all of your grat suggestion...they are really a great help.

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User last edited by A Former User

                        Or see Save Attachment

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