├── tedist ├── reabbrev ├── tetable ├── teprefix └── README.md /tedist: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # encoding: utf-8 3 | 4 | """ 5 | Read a .textexpander snippet file and generate a .tedist file with standardized prefixes. 6 | """ 7 | 8 | import plistlib 9 | import sys 10 | import os.path 11 | 12 | # Extract folder and filename 13 | infile = sys.argv[1] 14 | prefix = sys.argv[2] 15 | basename, extension = os.path.splitext(infile) 16 | 17 | # Make sure it's a TextExpander file. 18 | if extension != '.textexpander': 19 | print("%s is not a TextExpander file." % infile) 20 | sys.exit(-1) 21 | 22 | # Generate the new filename. 23 | tedist = basename + '.tedist' 24 | 25 | # Parse the snippet file 26 | try: 27 | te = plistlib.readPlist(infile) 28 | except IOError: 29 | print("Couldn't open %s to read from." % infile) 30 | sys.exit(-1) 31 | 32 | # Go through the snippets, replacing each prefix with [[PREFIX]]. 33 | for i in range(len(te['snippetsTE2'])): 34 | prelength = len(prefix) 35 | if te['snippetsTE2'][i]['abbreviation'][0:prelength] == prefix: 36 | te['snippetsTE2'][i]['abbreviation'] = '[[PREFIX]]' + \ 37 | te['snippetsTE2'][i]['abbreviation'][prelength:] 38 | 39 | # Write out the new .tedist file. 40 | try: 41 | plistlib.writePlist(te, tedist) 42 | print "wrote:", tedist 43 | except IOError: 44 | print "Couldn't write new textexpander file", tedist 45 | 46 | -------------------------------------------------------------------------------- /reabbrev: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # encoding: utf-8 3 | 4 | """ 5 | Attempt to read the contents of a .textexpander plist file, and generate a new file with the user's abbreviations of choice. 6 | """ 7 | 8 | import plistlib 9 | import sys 10 | import os.path 11 | 12 | # Extract folder and filename 13 | infile = sys.argv[1] 14 | basename, extension = os.path.splitext(infile) 15 | 16 | # Make sure it's a TextExpander file. 17 | if extension != '.textexpander': 18 | print("%s is not a TextExpander file." % infile) 19 | sys.exit(-1) 20 | 21 | # Generate the new filename. 22 | outfile = basename + "-2" + extension 23 | 24 | # Parse the snippet file. 25 | try: 26 | te = plistlib.readPlist(infile) 27 | except IOError: 28 | print("Couldn't open %s to read from." % infile) 29 | sys.exit(-1) 30 | 31 | # Go through the snippets, allowing the user to change each abbreviation. 32 | for i in range(len(te['snippetsTE2'])): 33 | print 'Label: ' + te['snippetsTE2'][i]['label'] 34 | newabbrev = raw_input( 35 | 'Abbreviation [' + te['snippetsTE2'][i]['abbreviation'] + ']: ') 36 | if newabbrev != '': 37 | te['snippetsTE2'][i]['abbreviation'] = newabbrev 38 | print 39 | 40 | # Write out the new .textexpander file. 41 | try: 42 | plistlib.writePlist(te, outfile) 43 | print "wrote:", outfile 44 | except IOError: 45 | print "Couldn't write new textexpander file", outfile 46 | sys.exit(-1) 47 | 48 | -------------------------------------------------------------------------------- /tetable: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # encoding: utf-8 3 | 4 | """ 5 | Read a .textexpander snippet file and generate a Markdown table 6 | that describes its contents. Useful for short snippets only. 7 | """ 8 | 9 | import plistlib 10 | import sys 11 | import os.path 12 | import getopt 13 | 14 | usage = '''Usage: tetable [option] tefile 15 | 16 | Create a table that describes a TextExpander library. 17 | 18 | Options: 19 | -m, --markdown Markdown table (default) 20 | -t, --tab Tab-separated table 21 | -w, --web HTML table 22 | -h, --help Show this usage message. 23 | ''' 24 | 25 | # Get the arguments from the command line. 26 | try: 27 | optlist, args = getopt.getopt(sys.argv[1:], 'hmtw', ['help', 'markdown', 'tab', 'web']) 28 | except getopt.GetoptError, err: 29 | print str(err) 30 | print usage 31 | sys.exit(2) 32 | 33 | # Process the options. 34 | tableType = 'markdown' 35 | for o, a in optlist: 36 | if o in ('-t', '--tab'): 37 | tableType = 'tab' 38 | elif o in ('-w', '--web'): 39 | tableType = 'web' 40 | elif o in ('-m', '--markdown'): 41 | tableType = 'markdown' 42 | else: 43 | print usage 44 | sys.exit() 45 | 46 | # Extract folder and filename. 47 | try: 48 | infile = args[0] 49 | basename, extension = os.path.splitext(infile) 50 | except IndexError: 51 | print "No input filename." 52 | print usage 53 | sys.exit() 54 | 55 | # Make sure it's a TextExpander file. 56 | if extension != '.textexpander': 57 | print("%s is not a TextExpander file." % infile) 58 | sys.exit(-1) 59 | 60 | # Parse the snippet file 61 | try: 62 | te = plistlib.readPlist(infile) 63 | except IOError: 64 | print("Couldn't open %s to read from." % infile) 65 | sys.exit(-1) 66 | 67 | # The table header. 68 | header = {'tab': 'To insert\tType', 69 | 'web': '\n', 70 | 'markdown':'| To insert | Type |\n|:-----:|:----:|'} 71 | # The row templates 72 | row = {'tab': '%s\t%s', 73 | 'web': '', 74 | 'markdown': '| %s | %s |'} 75 | 76 | # The table footer. 77 | footer = {'tab': '', 78 | 'web': '
To insertType
%s%s
', 79 | 'markdown': ''} 80 | 81 | # Print the table. 82 | print header[tableType] 83 | for i in range(len(te['snippetsTE2'])): 84 | print row[tableType] % (te['snippetsTE2'][i]['plainText'], te['snippetsTE2'][i]['abbreviation']) 85 | print footer[tableType] 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /teprefix: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # encoding: utf-8 3 | 4 | """ 5 | Read a .textexpander snippet file and generate a new one with a different abbreviation prefix. 6 | """ 7 | 8 | import plistlib 9 | import sys 10 | import os.path 11 | import getopt 12 | 13 | usage = '''Usage: teprefix [options] tefile 14 | 15 | Create a new TextExpander file with different abbreviation prefixes. 16 | 17 | Options: 18 | -o The old prefix, i.e., the one that's used in 19 | --old= the existing TextExpander file. It's best 20 | to enclose the prefix in single quotes to 21 | avoid interpretation by the shell. Default is 22 | the empty string. 23 | 24 | -n The new prefix, i.e., the one you want to use. 25 | --n= Again, it's best to enclose the prefix in single 26 | quotes to avoid interpretation by the shell. 27 | Default is the empty string. 28 | 29 | -h, --help Show this usage message. 30 | ''' 31 | 32 | # Get the arguments from the command line. 33 | try: 34 | optlist, args = getopt.getopt(sys.argv[1:], 'o:n:h', ['old=', 'new=', 'help']) 35 | except getopt.GetoptError, err: 36 | print str(err) 37 | print usage 38 | sys.exit(2) 39 | 40 | # Process the options. 41 | oldprefix = ''; # default 42 | newprefix = ''; # default 43 | for o, a in optlist: 44 | if o in ('-o', '--old'): 45 | oldprefix = a 46 | elif o in ('-n', '--new'): 47 | newprefix = a 48 | else: 49 | print usage 50 | sys.exit() 51 | 52 | # Extract folder and filename. 53 | try: 54 | infile = args[0] 55 | basename, extension = os.path.splitext(infile) 56 | except IndexError: 57 | print "No input filename." 58 | print usage 59 | sys.exit() 60 | 61 | # Make sure it's a TextExpander file. 62 | if extension != '.textexpander': 63 | print("%s is not a TextExpander file." % infile) 64 | sys.exit(-1) 65 | 66 | # Generate the new filename. 67 | outfile = basename + '-new.textexpander' 68 | 69 | # Parse the snippet file 70 | try: 71 | te = plistlib.readPlist(infile) 72 | except IOError: 73 | print("Couldn't open %s to read from." % infile) 74 | sys.exit(-1) 75 | 76 | # Go through the snippets, replacing each oldprefix with newprefix. 77 | for i in range(len(te['snippetsTE2'])): 78 | prelength = len(oldprefix) 79 | if te['snippetsTE2'][i]['abbreviation'][0:prelength] == oldprefix: 80 | te['snippetsTE2'][i]['abbreviation'] = newprefix + \ 81 | te['snippetsTE2'][i]['abbreviation'][prelength:] 82 | 83 | # Write out the new .textexpander file. 84 | try: 85 | plistlib.writePlist(te, outfile) 86 | print "Wrote:", outfile 87 | except IOError: 88 | print "Couldn't write new textexpander file", outfile 89 | 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Tedist is a simple Python script for taking your [TextExpander][2] snippet groups and putting them in a form suitable for inclusion in the [TE-Snippets][1] community site. 2 | 3 | Many people who use TextExpander regularly have a naming convention they use with all their snippets. My snippets, for example, always start with a semicolon. Brett Terpstra's always start with a pair of commas. The idea is to use a prefix that's both easy to type—so it takes little effort to use—and will never show up in the course of your normal writing or programming—so your snippets don't expand accidentally. 4 | 5 | The TE-Snippets site will have a collection of snippet libraries that can be customized to fit whatever prefix you like. To do that, the libraries are stored on the site in a special form, called the `.tedist` form. It's almost the same as the `.textexpander` file that TextExpander creates when you "Save a Copy" of a group of snippets. The difference is that the `.tedist` file has the special code `[[PREFIX]]` at the front of all the abbreviations. When a user downloads the library, that `[[PREFIX]]` is replaced with the user's prefix of choice. 6 | 7 | The purpose of the tedist script is to read in a normal `.textexpander` file and generate a new `.tedist` file for upload to the TE-Snippets site. It takes two arguments: 8 | 9 | 1. The name of the `.textexpander` file to convert. 10 | 2. The prefix used in the `.textexpander` file. 11 | 12 | For safety on the Unix command line, you should probably enclose the prefix in single quotes. 13 | 14 | Thus, to prepare my Symbols snippet library for TE-Snippets, I'd run this, 15 | 16 | tedist Symbols.textexpander ';' 17 | 18 | and I'd get a new `Symbols.tedist` in the same directory. 19 | 20 | Teprefix is a script for directly changing the abbreviation prefix from one string to another. It's meant to be used on snippet libraries that haven't been standardized to the `.tedist` form. To change from my form to Brett's, you'd run 21 | 22 | teprefix -o ';' -n ',,' Symbols.textexpander 23 | 24 | and you'd get a Symbols-new.textexpander file with double comma prefixes. Teprefix has a help message that explains the options and the defaults. 25 | 26 | If you want to change more than just the prefix, run `reabbrev`. It loops through all the snippets in the given file and allows you to change the abbreviation of each one. A session would look like this: 27 | 28 | reabbrev Symbols.textexpander 29 | Label: ½ 30 | Abbreviation [;1/2]: 31 | 32 | Label: ¼ 33 | Abbreviation [;1/4]: 1//4 34 | 35 | Label: ⅛ 36 | Abbreviation [;1/8]: 1//8 37 | 38 | Label: ¾ 39 | Abbreviation [;3/4]: 3//4 40 | 41 | and so on. The current abbreviation is given in square brackets. If you just hit the return key, the current abbreviation is retained; if you type anything else (and then hit the return key), that will be the new abbreviation. The new library will *not* overwrite the old one; it will be saved with the same name, but with a "-2" appended. In the example above, the new file will be "Symbols-2.textexpander." 42 | 43 | `Tetable` is a script for printing out a tabular description of a TextExpander library. The table can take the form of 44 | 45 | 1. A Markdown table (default) 46 | 2. A tab-separated table 47 | 3. An HTML table 48 | 49 | The output will look something like this 50 | 51 | | To insert | Type | 52 | |:-----:|:----:| 53 | | € | ;euro | 54 | | £ | ;pound | 55 | | ¢ | ;cent | 56 | | ′ | ;ft | 57 | | ″ | ;in | 58 | 59 | for the default Markdown output. Because `tetable` isn't particularly clever about linebreaks, it's best used on libraries that have short snippets. 60 | 61 | [1]: http://te-snippets.com/ 62 | [2]: http://smilesoftware.com/TextExpander/ 63 | --------------------------------------------------------------------------------