Skip to content

Instantly share code, notes, and snippets.

@geovanisouza92

geovanisouza92/README.md

Last active Apr 30, 2016
Embed
What would you like to do?
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)
@veg-max

This comment has been minimized.

Copy link

@veg-max veg-max 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
You can’t perform that action at this time.