I wrote a Python program that parses Preview.app‘s bookmarks. The program itself is probably of dubious use, but it illustrates some interesting techniques like using class-dump
to figure out how programs written in Objective-C work and how to use PyObjC to write Cocoa-style code with Python.
https://github.com/msabramo/print_os_x_preview_app_bookmarks
PyObjC allows you to write Python code that access the Cocoa libraries in a fairly intuitive way. The trickiest part of writing the program was figuring out how the data archived in the plist file was archived, so that I could write code to unarchive it. How did I figure out what the data looks like?
1. Install class-dump.
$ brew install class-dump
2. Run it (The awk
is just to filter the output to show just the PVBookmark
class).
$ class-dump /Applications/Preview.app | awk '/@interface PVBookmark/, /@end/ { print; }' @interface PVBookmark : NSObject { NSString *_UUID; NSString *_parentUUID; PVFileReference *_file; NSDate *_fileModDate; NSString *_label; int _pageIndex; } - (id)initWithFilePath:(id)arg1 label:(id)arg2 pageIndex:(unsigned long long)arg3; - (void)dealloc; - (id)initWithCoder:(id)arg1; - (void)encodeWithCoder:(id)arg1; - (id)description; - (id)UUID; - (id)filePath; - (id)fileModificationDate; - (id)label; - (void)setLabel:(id)arg1; - (unsigned long long)pageIndex; - (id)targetExists; - (BOOL)targetIsOnNetworkVolume; - (id)displayPath; - (unsigned long long)pageNumber; @end