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.


    Programmatically Reading Plist Files to Access External Files in Pythonista

    Pythonista
    modules file handling
    5
    10
    7865
    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.
    • az
      az last edited by

      I would like to create a script that can work with files loaded in Pythonista's "external files" section. I believe the information needed for this is stored in Bookmarks.plist in the app's root directory. I also believe I need plistlib to parse it. However, when I use readPlist, and take the 0 indexed item, it appears that that it contains a lot of \0x's and other various nonsense in between the pieces of data I need. How do I convert this data to a readable format? Thanks in advance for any help!

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

        Why not provide us with the code that you have written so far? That would help us to see what you are seeing without having to rewrite it.

        str.replace(substr, ‘’) might be part of the solution.

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

          @ccc This is what I have so far:

          import os, plistlib
          path = os.path.expanduser('~/Bookmarks.plist')
          dataparsed = plistlib.readPlist(path)
          print(dataparsed[0])
          
          mikael 1 Reply Last reply Reply Quote 0
          • mikael
            mikael @az last edited by

            @az, readList seems to be deprecated, use load instead. Have you tried providing an explicit fmt?

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

              https://docs.python.org/3/library/plistlib.html

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

                I think that file is special in some way -- i could duplicate the problem, and also my attempts at using objc failed to produce a clean dictionary. @ccc does his code (or replacing readPlist with plistlib.load(open(path,'rb')) work for you? it seems the plist represents an array of NSData for some unknown structure, but not an objc object like a dict. very odd..

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

                  Try this, worked for me (no iPad around to test it now).

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

                    @zrzka That code worked for me. However, why does the following code work? Is it the data type in the file that requires this? Where are methods like this documented so I can use them in the future?

                    NSURL.URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(
                    			ns(data.data), 1 << 8, None, None, None
                    			)
                    

                    Thanks again everyone!

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

                      Locating Files Using Bookmarks - ObjC runtime & iOS developer guide are your friends to look for.

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

                        @zrzka Cool, thanks!

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