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
    11906
    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.
    • iBayern
      iBayern last edited by iBayern

      Let say that we have a file named 'a.txt' saved in goodreader app. Can we read this file from pythonista without importing it? Using "Dropbox file picker" is th only way I figured out to import a file to pythonista...

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

        It depends on whether goodreader supports a Share Sheet in a real way.

        Does GoodReader have the "share" button? If so, try clicking it, then "Run Pythonista Script". Then, click on Scratchpad and type

        import appex
        print appex.get_attachments()
        

        then press play. If goodreader actually supports sharing, then you will see a file of the form /private/..... you should be able to then use

        text=open(appex.get_attachments()[0]).read()
        open('a.txt','w').write(text)
        

        then it should be there in pythonista when you return to the app. This of course can all be put into a script that you add to your app extension list of saved scripts to avoid some of the tedium.

        1 Reply Last reply Reply Quote 3
        • 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