Skip to content

Instantly share code, notes, and snippets.

@Luzifer
Created September 17, 2012 12:21
Show Gist options
  • Save Luzifer/3736991 to your computer and use it in GitHub Desktop.
Save Luzifer/3736991 to your computer and use it in GitHub Desktop.
Little python script to export your dashboard stickies to text only format to copy to another location
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment