Programmatically Reading Plist Files to Access External Files in Pythonista
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.plistin the app's root directory. I also believe I need
plistlibto 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!
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.
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)
mikael last edited by
readListseems to be deprecated, use
loadinstead. Have you tried providing an explicit
ccc last edited by
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..
zrzka last edited by zrzka
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!
zrzka last edited by
Locating Files Using Bookmarks - ObjC runtime & iOS developer guide are your friends to look for.
@zrzka Cool, thanks!