Dashes to Spaces & Word Caps using TextExpander

When uploading my artwork to Flickr, I typically have a file name that I want to use for the title as well. The problem is, when doing a Save For Web from Photoshop or Illustrator, I have things set up so the filenames are web-friendly (all lowercase, and dashes instead of spaces between words). So when the files get uploaded, Flickr defaults to using those filenames and manually editing the text is a waste of time. Here’s how I streamlined that process.

First, I enlisted the help of my illustrator friend and coding wiz Greg Newman to make me a shell script that would do what I needed: convert dashes to spaces, then capitalize all the words. Here’s the simple script, which works with the contents of the Clipboard and so requires a manual Copy action to be performed prior to running the script:

 #! /usr/bin/python

cliptext = "%clipboard"
 print cliptext.replace('-', ' ').replace('%', ' ').replace('&', ' and ').replace('#', ' ').title()

Next, I set up a new TextExpander snippet, making sure to change the “Content:” drop-down menu to shell script:

To use this, you just need to highlight the text you want to convert, copy it, then invoke the snippet with the abbreviation you set for it (in this example, dsp// is the abbreviation).

I’ll be honest, I have no idea how to do shell scripting and have no idea how this works. I’ve been wanting to set up something similar as an Automator action, but have no idea how to edit this to use within Automator. If you can help out, please let me know in the comments section. Ideally, it would work on the selected text and have no need for the user to have to manually copy the text to the Clipboard.

Update: a helpful user over at Stack Exchange’s Ask Different supplied me with the method (and Python script) to accomplish this using Automator. By creating this as a Service in OS X, it can be assigned a custom keyboard shortcut command, and the conversion can be performed on the highlighted text with no need for copying to the Clipboard. Perfect!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s