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
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!
- Your name and email address are required, but your email will not be displayed on the site
- If you provide a URL, a link to your site will appear
- You may use the following HTML:
<strong>bold</strong><em>italic</em><a href="http://url">links</a>
- Double line breaks will be converted to paragraphs.
- As you type, you should get a nice little preview of your comment directly below the text box.
- I reserve the right to edit any comment for any reason (I’ll be reasonable).
Recently Played on iTunes
-
“Heroin”
The Velvet Underground & Nico
The Velvet Underground
11/17/08 16:26 -
“All Tomorrow's Parties”
The Velvet Underground & Nico
The Velvet Underground
11/17/08 16:20 -
“Run Run Run”
The Velvet Underground & Nico
The Velvet Underground
11/17/08 16:16
Nate:
Dude, That script just saved me about 5 hours of work. Thank you so much.
Nate
03/04/05 3:53PM