Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Shell Script to alter text case, etc..

Shell Script to alter text case, etc..
Thread Tools
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Mar 10, 2005, 03:54 PM
 
Hi, I'm looking for a way to take some clipboard text and change it's case to UPPER or Initial Caps, or all lowercase.

Any ideas or links?
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Mar 10, 2005, 07:01 PM
 
Since you titled this with "shell script" here is a quick one to change the contents of the (unstyled) pasteboard to all upper-case:
Code:
pbpaste | awk '{print toupper($0)}' | pbcopy
or to all lower case:
Code:
pbpaste | awk '{print tolower($0)}' | pbcopy
This is only good when it is text only. If that text is styled, then the pasteboard will contain rtf, and this script will go bad in many ways. You could in theory write a awk command that would avoid the rtf command strings, but that is not worth my time.

I have a feeling that you would probably be better with an AppleScript to get the current selection and apply some text transforms, but you never really said what you want to do with this.
     
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Mar 11, 2005, 07:10 AM
 
Thanks! It's a great place for me to start.
     
Addicted to MacNN
Join Date: Jun 1999
Location: Las Vegas, NV, USA
Status: Offline
Reply With Quote
Mar 11, 2005, 07:24 AM
 
Try WordService.

Chris
     
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Mar 11, 2005, 01:55 PM
 
Originally posted by headbirth:
Hi, I'm looking for a way to take some clipboard text and change it's case to UPPER or Initial Caps, or all lowercase.

Any ideas or links?
Hey that's a fun one, lemme try!

To uppercase:
Code:
pbpaste | tr 'a-z' 'A-Z' | pbcopy
To lowercase:
Code:
pbpaste | tr 'A-Z' 'a-z' | pbcopy
Initial Caps... I don't know sed, awk, and tr well enough... haha. I'll play with it, though.
"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Mar 11, 2005, 09:48 PM
 
WordService is great ... but I'm actually trying to write some of it's functionality into an OnMyCommand CM menu so the actions are available in the CM and the keystrokes don't conflict with apps.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:50 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2