August 27, 2009 Creating a ‘Make Title Case’ Service in Snow Leopard

Inspired by the Services overview on the Mac OS X Automation website (via John Gruber), I decided to take a crack at creating my own system-wide service for converting text to title case — utilizing, of course, John Gruber’s TitleCase script.

I’m not a programmer, and the little programming knowledge I do have is strictly front-end web development, so the thought of setting up a Service like this, where I can easily convert text to title case, was very appealing. Even more appealing was the fact that I could easily show how anyone could do this.

What you need

First, here’s what you need:

Creating the Service

The Mac OS X Automation website has a tutorial on how to create a Service in Snow Leopard, but you really only need to skim the photos to understand the process. Apple’s made it easier than saving 15% on your car insurance.

After downloading the TitleCase script, launch Automator. Choose ‘Service’ in the template manager, and you’ll be presented with an Automator workflow creator window.

automator-snowleopard.jpg

Leave “text” and “any application” selected in the building pane, but check the “Replaces selected text” box.

Now search the actions library for “script”, and then drag the “Run Shell Script” action to the workflow pane. It should be the last item in the search results.

Now, open the TitleCase.pl script in a text editor (Text Edit works just fine), and copy the entire script.

Back in Automator, select “/usr/bin/perl” in the Run Shell Script action; in the ‘shell’ drop down menu. Select the entire sample print script that shows up, and delete it. Now paste the TitleCase.pl script.

Save (File > Save), title, and enjoy! Your new Service will be saved in the “Text” category of the Keyboard Shortcuts Preference Pane. From there you can assign a global keyboard shortcut.

Update: John points to a new version of his script by Aristotle Pagaltzis, which, he says, is ‘better in every way’. (Thanks to Jordan Yee for the tip in the comments below.)


Comments

This rocks.

I’m waiting for Smashing Magazine or someone to host the “Top 20 Most Useful Service Scripts” soon… services = amazing.

Jesse J. Anderson
August 28, 2009

The new Services menu is awesome. I’ve already created a ton of new Services along these lines using Python.

Carl
September 7, 2009

This new Services functionality is seriously tempting me to buy the Snow Leopard upgrade.

Bryce
September 7, 2009

Great article, thanks – before now I’d overlooked all the Services praise as hype. After seeing how useful this is, I’m off to watch the PixelCorps videos on automation.

Alex Muller
September 7, 2009

Why copy and paste the contents of the Perl script into the Automator workflow, instead of just calling it?

Michael Barber
September 7, 2009

Michael – so you don’t have to keep the file hanging around.

Jesse J. Anderson
September 7, 2009

I’ve tried this exactly as is but when I run it it just deletes the text. Any ideas what I might be doing wrong?

Thomas Fitzgerald
September 7, 2009

Thomas, it happened to me as well, using Aristotle Pagaltzis’ improved code solved the problem for me. You can find the link to it in John’s script.

Travis Lupin
September 7, 2009

What is title case?

Slim
September 7, 2009

Travis – Cool, that worked! Thanks

Thomas Fitzgerald
September 7, 2009

Excellent!

Slim – Title Case is the First Letter of Every Word Capitalized Except for Words Like ‘a’, ‘the’, ‘an’, etc…

Michael
September 8, 2009

ha ha very happy..that worked for me too…

sachin
September 8, 2009

Very smooth! About time we had a good user-level use for powerful scripting languages on the Mac.

Goldarn
September 8, 2009

The only thing this script doesn’t do is title case items that are already in all capital letters. Anyone have a recommendation as to how to tweak the perl script?

Lon Seidman
September 8, 2009

Quite timely. Just today I re-read Chapter 7 of Joe Zobkiw’s book “Mac OS X – Advanced Development Techniques” which shows how to change text to upper case, lower case, or capitals. However, the book came out in 2003, so the approach was certainly more Cocoa-centric, since Automator wasn’t even around yet.

Chad
September 8, 2009

Works great in text apps, but why doesn’t this show up in Word?

brett
September 11, 2009

Thanks for the nice little guide. FYI though, John Gruber has pointed out that “[Aristotle Pagaltzis’] result is better than my original script in every way.”

Here’s a link to Pagaltzis’ script home if you want to update this page.

http://plasmasturm.org/code/titlecase/

Jordan Yee
May 23, 2010

Works great in text apps, but why doesn’t this show up in Word?

Oyunlar
June 19, 2010

Yes it works! Thank you a lot!
You made me very happy.

Nieuws
June 26, 2010

That works really great.Thanks for the great stuff.

Chicago movers
August 26, 2010

Add a Comment

Textile guide:

*strong/bold*
_emphasis/italics_
bq. blockquote
"link":http://...
Numbered list: #
Unordered list: *