TextExpander snippet to replace spaces with dashes


UPDATE: I’ve updated this to a version which you can use inside other snippets. You can find that here.

A good while back I started naming files with dashes as opposed to spaces, in case I ever had to put them on the web. (I don’t like %20 signs…)

This is a shell script that you can use with TextExpander which replaces spaces with dashes in whatever input it gets from a fill-in field.

<code>#!/usr/bin/env python
import sys
var = '%filltext:name=Title%'
dashedvar = var.replace(" ", "-");
sys.stdout.write(dashedvar)
</code>

For some reason you can’t use this snippet inside other snippets, I’m not sure why. (Let me know if you do!) So I have other specific snippets which are similar in cases where I want more than just conversion of whatever I type in. Here’s the one I use for naming blog text files:

<code>#!/usr/bin/env python
import sys
var = '%filltext:name=Title%'
dashedvar = var.replace(" ", "-");
sys.stdout.write('blogx-%snippet:sdate%-')
sys.stdout.write(dashedvar)
</code>

(If you’re wondering why I’m using sys.stdout.write instead of print it’s to avoid the newline that print adds at the end.)