Skip to content

Instantly share code, notes, and snippets.

@jmontrose
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmontrose/e908f46188be38b86767 to your computer and use it in GitHub Desktop.
Save jmontrose/e908f46188be38b86767 to your computer and use it in GitHub Desktop.
quick hack to batch export from ulysses into simple plain text
#!/usr/bin/env python
import os
import glob
import plistlib
def cleanse(text):
body = text
body = body.replace('\xe2\x80\x99', "'")
body = body.replace('\xe2\x80\x9c', '"')
body = body.replace('\xe2\x80\x9d', '"')
body = body.replace('\xe2\x80\x98', "'")
body = body.replace('\xe2\x80\xa6', "'")
body = body.replace('\xe2\x80\xa8', "")
return body
def output_group(group_dir):
chunks = []
group_info = plistlib.readPlist(os.path.join(group_dir, 'Info.ulgroup'))
for subdirs in group_info.get('sheetClusters', []):
for subdir in subdirs:
text_name = os.path.join(group_dir, subdir, 'Text.txt')
chunks.append(cleanse(open(text_name).read()))
if not chunks[-1].endswith('\n\n'):
chunks.append('\n\n')
for child in group_info.get('childOrder', []):
if not child.endswith('-ulgroup'):
continue
chunks.extend(
output_group(os.path.join(group_dir, child)))
return chunks
ulysses_root = glob.glob(os.path.expanduser('~/Library/Mobile Documents/*com~soulmen~ulysses3/Documents/Library/Groups-ulgroup'))[0]
output_root = os.path.expanduser('~/src/writing/ulysses')
for group_dir in glob.glob(os.path.join(ulysses_root, "*-ulgroup")):
group_info = plistlib.readPlist(os.path.join(group_dir, 'Info.ulgroup'))
body = ''.join(output_group(group_dir))
open(os.path.join(output_root, group_info['displayName'] + '.md'), 'w').write(body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment