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!
Forum Archive
Programmatically Reading Plist Files to Access External Files in Pythonista
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.
@ccc This is what I have so far:
import os, plistlib
path = os.path.expanduser('~/Bookmarks.plist')
dataparsed = plistlib.readPlist(path)
print(dataparsed[0])
@az, readList seems to be deprecated, use load instead. Have you tried providing an explicit fmt?
https://docs.python.org/3/library/plistlib.html
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..
Try this, worked for me (no iPad around to test it now).
@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!
Locating Files Using Bookmarks - ObjC runtime & iOS developer guide are your friends to look for.
@zrzka Cool, thanks!