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 (11)

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

Thank you so much for these -- I had been going to Sublime Text to do all of this before.

THIS IS GOING TO BE SO HELPFUL! (Ha, see what I mean!)

I have one other one that I consider along these same lines which I think a lot of Text Expander users might already know, which is just "Plaint Text Paste"

Basically, if you copy formatted text to the clipboard from somewhere, it will strip all of that junk out and just repaste the clipboard as plain text.

The text expander snippet is just: %clipboard

Obviously not as exciting, but definitely useful.

April 30, 2014 | Unregistered Commenterjoebot

I really want to get this working. So I imported the group into TextExpander for Mac (V. 4.3.2).
In another snippet I want to use the clipboard text in lower case: (I copy the invoice number and want all letters in small caps)

---
rechnung %lclip

or

rechnung %lclip%
---

Both don't work. It will always give me "rechnung %lclip" or "rechnung %lclip %" as return.

Any ideas?

August 7, 2014 | Unregistered CommenterR. Knudsen

Thanks for posting these, they are incredibly useful! I've been trying to adapt this slightly, but have failed miserably, so I thought I'd ask you if you can see a way to achieve it…

What I'd like to achieve is a TextExpander snippet that opens a Single-line field for text input, and which will then transform that text to uppercase. (This is both a time saver over pushing or holding caps lock, and means I don't have to remember this particular thing should have been in caps.) I can imagine others might also find this useful, perhaps especially for title case etc.

I have been trying to do this using "nested snippets", but have been unable to take the text just typed and to convert that to uppercase by this route.

Can you suggest a way this could be done? Perhaps not, but thanks for posting these even so!

August 17, 2014 | Unregistered CommenterMark Knight

Love it extremely easy and especially Paste Clipboard Text (Title/Proper case) VERY useful for posting on social media Where Short Messages Get Higher Impact When First Letter Capitalized
I am struggling on 1 thing though:
Would you know a reason why this does not work on cyrillic and only latin characters ?
That is strange
For example Просмотреть это письмо в браузере remains the same and э from это and б from браузере do not get capitalized
Any idea on what I should do to make it work in cyrillic same as latin ?
Thanks much from France! (not too far from Moscow...)
Alexandre

October 14, 2014 | Unregistered CommenterAlexandre

Hi Mark.

I don't know of any way to do this in TextExpander. I'd probably use keyboard Maestro to get the user input and run a conversion script.

Regards,

Stephen.

February 24, 2015 | Registered CommenterStephen Millard

Hi Alexandre.

I think it might be because Cyrillic would use a unicode character set and Perl's support by default I don't think includes support for this. I'm not a Perl guru so don't quote me on that, but there's some more information here.

February 25, 2015 | Registered CommenterStephen Millard

Hi R. Knusden.

I'd guess you have not set the snippet to be a script but rather to just be a text based snippet. Try checking the snippet's content format.

February 25, 2015 | Registered CommenterStephen Millard

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>