Other Entries

Log

AppleScript to Replace Raw Smart Quotes with HTML Entities in BBEdit

After banging my head against the wall trying to figure out a regular expression in a perl script to replace smart quotes with their appropriate entities in BBEdit, I wrote the following AppleScript to search for and replace smart quotes and apostrophes with their html equivalents. Very useful for copying and pasting content from word docs. Paired with SmartyPants and MarkDown, all you need for fast markup of client-provided content.


tell application "BBEdit"
  set searchOptions to  {search mode:literal, ¬
    starting at top:true, wrap around:false, ¬
    reverse:false, case sensitive:false, ¬
    match words:false, extend selection:false}
  activate
  replace "“" using "“" ¬
    searching in text 1 of text window 1 options searchOptions
  replace "”" using "”" ¬
    searching in text 1 of text window 1 options searchOptions
  replace "’" using "’" ¬
    searching in text 1 of text window 1 options searchOptions
  replace "‘" using "‘" ¬
    searching in text 1 of text window 1 options searchOptions
  replace "–" using "–"  ¬
    searching in text 1 of text window 1 options searchOptions
  replace "—" using "—"  ¬
    searching in text 1 of text window 1 options searchOptions
end tell

(Lines wrapped at ¬ for legibility.)

Just save to your BBEdit Application Support Scripts folder (~/Library/Application Support/BBEdit/Scripts/ for BBEdit 8 and /Applications/BBEdit/Application Support/Scripts/ for earlier versions) and it will be available in your scripts menu.

12/06/04 01:35PM Geekiness Macintosh

Comments

Nate:

Dude, That script just saved me about 5 hours of work. Thank you so much.

Nate

03/04/05 3:53PM

snowbutterfly:

OMG. Bless you for writing this script. I’ve been hand replacing for YEARS and I’m finally discovering the use of scripts and automator.

i can’t, for the life of me, write any scripts or figure out how to make anything on my own in Automator, but thank TPTB and you ingenious peeps out there who can.

08/28/06 2:10PM

Add a Comment

Have something to say about what I wrote here? Let’s hear it!

The Rules

Personal Information




Remember Information


Comment Preview

 

 

Recently Played on iTunes

  1. “Heroin”
    The Velvet Underground & Nico
    The Velvet Underground
    11/17/08 16:26
  2. “All Tomorrow's Parties”
    The Velvet Underground & Nico
    The Velvet Underground
    11/17/08 16:20
  3. “Run Run Run”
    The Velvet Underground & Nico
    The Velvet Underground
    11/17/08 16:16

Last 100 Songs >