Using Shell Scripts to Extend TextExpander

Greg Scown Blog, TextExpander, TextExpander Tips

In addition to plain text and formatted text, pictures snippets, TextExpander also supports AppleScript and shell scripts as content types. Your abbreviation will expand to whatever the script returns. This allows you to extend TextExpander in whatever ways you need. Here’s a recent example which started with a support question:

> I've created the following snippet with abbreviation: ,getdate:

>

> %date:EEEE% %date:d% %date:LLLL% %date:Y% - día %date:D% del año

>

> Which is converted to the following on my system:

>

> jueves 30 septiembre 2010 - día 273 del año

>

> However, I would like the day of the week and month to be in uppercase, as follows:

>

> Jueves 30 Septiembre 2010 - día 273 del año

>

> Do you know how to do this?

It seems that the Unicode date formatting doesn’t offer a way to specify that the month or day names should be returned in uppercase.

I was able to write a Perl script and to nest the ,getdate snippet to convert the first and third words to uppercase. I set my abbreviation to ,date and my Content: to Shell Script:

#!/usr/bin/perl

$_ = "%snippet:,getdate%";

m/(\S+) (\S+) (\S+)(.*)/;

$_ = ucfirst($1) . " $2 " . ucfirst($3) . "$4";

print "$_\n";

Here is what ,date returns right now with my system set to return date information in Spanish:

Miércoles 13 Octubre 2010 – día 286 del año

That which wasn’t possible before is possible now, thanks to the power of shell scripts in TextExpander.