Search
« The Ideal Twitter Client Top 10 Feature List | Main | Using SED on Windows »
Saturday
Oct012011

TextExpander: Change Clipboard Case


On Windows I have a useful function in one of my text editors that takes some text and converts the case - to upper case, lower case or sentence case. I realised that on the Mac I could use TextExpander to carry out these functions, so if you're a TextExpander user and want to have this functionality available to you, I've provided some details and a downloadable snippet group for you to use.



In order to produce this functionality we're going to use the clipboard as the place to hold the text we wish to run the conversion on. This means that the first thing you'll need to do is copy your text.



In order to process the text I found the easiest way was to use some little PERL scripts. Fortunately TextExpander provides us with a way to call PERL scripts and return the results to insert. This is setting the snippet to a content type of "Shell Script" and using the 'print' command to output the result.



The snippet group can be downloaded form the link below and installed into your own copy of TextExpander. You may also want to check out my earlier post on how to import and export snippet groups in TextExpander.




 Details of each of the snippets are given below.





Label Paste Clipboard Text (Lower case)
Description Alphabetic characters are converted to lower case alphabetic.
E.g. "i am lower case. so i only have lower case characters."
Abbreviation %lclip
Content
#!/usr/bin/perl -w

#Initialise
use strict;
my($text);

#Get the text from the clipboard
$text =`pbpaste`;

#Output the text as lowercase
print "\L$text";



Label Paste Clipboard Text (Upper case)
Description Alphabetic characters are converted to upper case alphabetic.
E.g. "I AM UPPER CASE. SO I ONLY HAVE UPPER CASE CHARACTERS."
Abbreviation %uclip
Content
#!/usr/bin/perl -w

#Initialise
use strict;
my($text);

#Get the text from the clipboard
$text =`pbpaste`;

#Output the text as uppercase
print "\U$text";
Label Paste Clipboard Text (Sentence case)
Description The first character is converted to upper case alphabetic. The remaining characters are converted to lower case.
E.g. "I am sentence case. So i only have an upper case character at the start of each sentence, with the remaining alphabetic characters in each sentence being lower case."
Abbreviation %sclip
Content
#!/usr/bin/perl -w

#Initialise
use strict;
my($text);

#Get the text from the clipboard
$text =`pbpaste`;

#Convert the text to lower case
$text ="\L$text";

#Convert the first character of each sentence to upper case
$text =~ s/(^\w|\.\s+\w)/\U$1\E/g;

#Output the text
print $text;




Label Paste Clipboard Text (Title/Proper case)
Description The first character is converted to upper case alphabetic. The remaining characters are converted to lower case.
E.g. "I Am Title Case. So I Have An Upper Case Character At The Start Of Each Word, With The Remaining Alphabetic Characters In Each Word Being Lower Case."
Abbreviation %tclip
Content
#!/usr/bin/perl -w

#Initialise
use strict;
my($text);

#Get the text from the clipboard
$text =`pbpaste`;

#Convert the text to lower case
$text ="\L$text";

#Convert the first character of each word to upper case
$text =~ s/ ((^\w)|(\s\w))/\U$1/xg;

#Output the text
print $text;

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (4)

Thank you so much for these snippets. That was very thoughtful of you to post them. I had a feeling that text expander could do that, and you proved that assumption right.

You saved me a lot of time, now and in the future, so I wanted to be sure you knew you were appreciated. I especially like the title snippet, which I can use every time I type a Wordpress title.

May 10, 2012 | Unregistered CommenterRandall Soules

Thank you Sir!! These scripts are awesome and exactly what I needed! Thank you very much for posting them and adding to the overall greatness that is textexpander!

August 15, 2012 | Unregistered Commentercheap data recovery

Thank you very much for sharing these! I've used to fire up TextWrangler to change it (which is brilliant but took too much time for simple corrections).

May 30, 2013 | Unregistered CommenterPawel Glaz

Thank you for these; they are great time savers for me!

January 21, 2014 | Unregistered CommenterGeoff

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>