Skip to content

Instantly share code, notes, and snippets.

@geovanisouza92
Last active April 30, 2016 11:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geovanisouza92/f4651ab4c36a30399fad to your computer and use it in GitHub Desktop.
Save geovanisouza92/f4651ab4c36a30399fad to your computer and use it in GitHub Desktop.
Script to convert TextExpander snippets to Texpand

Usage:

$ ./te2t.py <.textpander file> <.txt file>

Import the .txt file into Texpand app.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=
#qpy:2
#qpy:console
import plistlib
import time
import json
import sys
if len(sys.argv) < 3:
print 'Please, inform the input and output file'
sys.exit(0)
mapping = {
'%d': '[day/n]',
'%m': '[month/n]',
'%Y': '[year/nf]',
'%clipboard': '[clipboard]',
}
def replace_mappings(text):
for k, v in mapping.iteritems():
text = text.replace(k, v)
return text
def convert(source):
target = {
'app_exclusions': [],
'phrases': [
{
'shortcut': snippet['abbreviation'],
'phrase': replace_mappings(snippet['plainText']),
'description': snippet['label'],
'usage_count': snippet['useCount'],
'timestamp': long(time.mktime(snippet['creationDate'].timetuple()) * 1000),
'expands_immediately': False,
'expands_within_word': False,
'disable_smart_case': False,
}
for snippet in source['snippetsTE2']
]
}
return json.dumps(target)
source = plistlib.readPlist(open(sys.argv[1]))
result = convert(source)
with open(sys.argv[2], 'w') as f:
f.write(result)
@lukaz-m
Copy link

lukaz-m commented Apr 30, 2016

Hi there ! I've been searching for something like this. How do I use it? My text expander snippets file is .textexpanderbackup . . Do I place the file inside the folder then run the command? Sorry for being such newbie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment