Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Pretty simple: I need a way to convert special characters like curly quotes, ellipses, etc to their "plain text" version, i.e. … to ..., “ to ".

This is on OS X, meaning I can't use a macro in Microsoft Word to do this as I have on a PC.

This is for a plain-text email, not HTML, which is why I need them in this format. Thank you.

share|improve this question

4 Answers 4

I see you want to do this in Mail. The best way to do this (imho) is with a Service Menu item. Word Service has an option to straighten/curly quotes.

If you're using Snow Leopard, it's pretty straightforward to create your own service menu item with a python/ruby/applescript to replace arbitrary special characters.

EDIT: Yeah I glossed over how to do this by saying it's "pretty straightforward" a bit disingenuously. Here's how to do it with a ruby script. ;-)

  1. Open Automator
  2. Create new Workflow, choose "Service" as your template
  3. Choose Service receives selected text in any application with the top popups
  4. Click the checkbox underneath: Replaces selected text
  5. Drag Run Shell Script from the left pane into your workflow
  6. With the Shell pupup select /usr/bin/ruby/
  7. Copy and paste in the following code, modify to your needs
  8. Save! Find it in the Services menu of your favourite application

    $KCODE = 'u'
    require 'jcode'
    # need the above two lines for ruby <1.9.1 
    # to make str.tr and str.gsub unicode aware
    
    
    # grab the selected text!
    theText = STDIN.gets(nil)
    
    
    # str.tr replaces single characters
    theText = theText.tr('“”','"')
    theText = theText.tr("‘’","'")
    
    
    # need to use str.gsub: replacement is > replaced characters
    theText = theText.gsub("…","...")
    theText = theText.gsub("—","--")
    
    
    # add more replacements as desired . . .
    
    
    STDOUT << theText  # replace da text!
    
share|improve this answer
1  
+1 for phasing the answer like you are an animated paperclip. –  stib May 8 '10 at 12:54
    
□ Don't Show me this tip again –  ghoppe May 11 '10 at 13:11
    
Looks good, but for some reason I get "No Services Apply" from the Services menu in Microsoft Word –  user36452 May 19 '10 at 20:27
    
Stupid MS Word isn't a Cocoa application but you can still code support for Services into Carbon applications. I hear Entourage supports services but Word does not. Sorry. I advise not using Word. :) You mentioned this was for a plain-text email why not just apply the service there? –  ghoppe May 19 '10 at 21:53
    
Or could you use a "Get Selected Content from Word Documents" action instead, as @Doug Harris has done with his shell script? –  ghoppe May 19 '10 at 21:57

The easy point-and-click way -- Bare Bones Software has a free text editor called "TextWrangler" that has a built-in "Convert to ASCII" command. You can even automate it: http://discussions.apple.com/thread.jspa?threadID=890344

The application also has regular expression search and replace, if you need it.

share|improve this answer

http://www.mbayer.de/html2text/

might be what you want.

For OS X, there's a macports port for it, if you have macports, use

sudo port install html2text

share|improve this answer

I've done this with an Automator workflow that:

  1. Uses the "Get Selected Content from Word Documents" action and passes that output to...
  2. "Run Shell Script" to use sed -e 's/“/"/g; s/”/"/g; s/…/.../g; ' -e "s/’/'/g" and passes that output to...
  3. "Copy to Clipboard" action

Save this script under ~/Documents/Microsoft User Data/Word Script Menu Items/ and it will appear in Word's script menu.

Just select the text you want to send, run the script, and then you can paste the cleaned text into an email.

share|improve this answer
    
Thanks, this works perfectly except that it looses the bold / italic / etc formatting when done in Word. –  user36452 May 19 '10 at 20:28
    
I don't understand. I thought you don't want any formatting because you're sending plain text email. –  Doug Harris May 20 '10 at 13:24
    
Ideally, I would like to keep any bold and italic formatting but remove the special characters as I could then paste this directly into a WYSIWYG editor, which I need to use as it keeps the bold/italic and also creates all the necessary line breaks. That would be for the HTML version. You are right that it wouldn't matter for the plain text version. –  user36452 May 20 '10 at 15:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.