Created
February 20, 2011 22:18
-
-
Save cspickert/836364 to your computer and use it in GitHub Desktop.
A PyObjC StickiesDatabase reader.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Foundation import * | |
from AppKit import NSAttributedString | |
import os | |
class Sticky(NSObject): | |
"""A Stickies document. | |
Attributes (from class dump): | |
int windowColor | |
int windowFlags | |
_NSRect windowFrame | |
NSDate *creationDate | |
NSDate *modificationDate | |
NSData *rtfdData | |
""" | |
stickiesDatabasePath = os.path.expanduser("~/Library/StickiesDatabase") | |
def initWithCoder_(self, aDecoder): | |
self.rtfdData = aDecoder.decodeObject() | |
self.windowFlags = aDecoder.decodeValueOfObjCType_at_("i") | |
self.windowFrame = aDecoder.decodeValueOfObjCType_at_("{_NSRect={_NSPoint=ff}{_NSSize=ff}}") | |
self.windowColor = aDecoder.decodeValueOfObjCType_at_("i") | |
self.creationDate = aDecoder.decodeObject() | |
self.modificationDate = aDecoder.decodeObject() | |
return self | |
def stringValue(self): | |
str, attrs = NSAttributedString.alloc().initWithRTFD_documentAttributes_(self.rtfdData, None) | |
return str.string() | |
@classmethod | |
def allStickies(self): | |
NSUnarchiver.decodeClassName_asClassName_("Document", NSStringFromClass(self)) | |
return NSUnarchiver.unarchiveObjectWithFile_(self.stickiesDatabasePath) | |
if __name__ == '__main__': | |
for sticky in Sticky.allStickies(): | |
# Do something useful | |
print sticky.stringValue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment