cfg/bin/exportstickies
2016-07-21 16:29:54 +02:00

23 lines
718 B
Python
Executable file

#!/usr/bin/env python
import json, subprocess, os, re, HTMLParser
exportcmd = 'plutil -convert json -o - %s' % os.path.expanduser('~/Library/Preferences/widget-com.apple.widget.stickies.plist')
out = json.loads(subprocess.check_output(exportcmd.split(' ')))
stickies = []
htmlparser = HTMLParser.HTMLParser()
for key in out.keys():
if not '-data' in key:
continue
html = out[key]
text = re.sub('\n+', '\n', '\n'.join(re.split(r'<[^>]*div>', html))).strip()
text = '\n'.join(re.split(r'<br[^>]*>\n?', text))
lines = text.split('\n')
lines = map((lambda parm: htmlparser.unescape(parm).strip()), lines)
text = '\n'.join(lines).strip()
stickies.append(text)
print '\n\n=====\n\n'.join(stickies)