[This is my second try at posting - apologies if you see it twice] On Wed, May 18, 2011 at 08:38, Bo <[email protected]> wrote: > How does one convert email and web addresses to hyperlinks using > BBEdit. >
I do it with the following Applescript. Caution: I'm not a scripting expert. The script has worked well for me for several years, but you should always check its output in case it does odd things for you. ================ -- This script turns selected text into a link. -- Select text like www.google.com or http://www.google.com -- or an email address like [email protected] -- and then run the script. -- by Miraz Jordan, http://knowit.co.nz tell application "BBEdit" make new text document with properties {contents:selection} at text window 1 tell front window -- set the static bits of code set h_ref to "<a href=\"http://" set last_bracket to "\">" set close_tag to "</a>" set mail_to to "mailto:" -- now we build the link -- delete any superfluous angle brackets replace "<" using "" replace ">" using "" select text 1 set selection to h_ref & selection & last_bracket & selection & close_tag -- clean up -- lose a trailing slash on the link text replace "/</a>" using "</a>" -- delete an http:// on link text replace ">http://" using ">" -- add an http:// to the link if necessary replace "href=\"www" using "href=\"http://www" -- add a mailto: to the link if necessary replace "href=\"(.+)@" using "href=\"mailto:\\1@" options {search mode:grep, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false} -- tidy replace " </a>" using "</a>" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false} replace "href=\"http://http://" using "href=\"http://" replace "href=\"mailto:http://" using "href=\"mailto:" -- return the URL to the old window set the_url to text 1 close active document saving no set selection to the_url select insertion point after selection say "Here's your link." end tell end tell ================ Cheers, Miraz -- MacTip: Project your iPad2 - http://mactips.info/2011/05/project-your-ipad2 KnowIT: Get some send some: try out torrents - http://knowit.co.nz/2011/05/get-some-send-some-try-out-torrents -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
