Subscribe to
Posts
Comments
NSLog(); Header Image

Safari, BBEdit AppleScript

I'm a big fan of AppleScript. After all, I do run AppleScript Central. So when things like this article pop up on the Web, I take note. Truth is, I've been using a similar AppleScript for a few weeks now (wow, Safari has been out that long?). Here it is:

set urlList to {"xxxxxxxxx"}
set textToInsert to "<a href=\""
tell application "Safari"
    set docList to every document
    repeat with d in docList
        copy URL of d to end of urlList
    end repeat
end tell
tell application "BBEdit"
    set theURL to choose from list urlList with prompt ¬
        "Insert Link from Safari window:" OK button name "Insert"
    if theURL is not false then
        set theTitle to text returned of (display dialog  ¬
            "Set title attribute to:" default answer "")
        set linkText to text returned of (display dialog  ¬
            "Set link text to:" default answer "")
        set textToInsert to textToInsert & theURL & "\"  ¬
            title=\"" & theTitle & "\" target=\"_blank\">" &  ¬
            linkText & "</a>"
        set selection of text window 1 to textToInsert
    end if
end tell

I use the "xxxxxxxxx" one when I need to insert my own URL but would like BBEdit to ask me for the title and link text.

Comments RSS

Leave a Reply


Warning: Undefined variable $user_ID in /var/www/vhosts/nslog.com/httpsdocs/wp-content/themes/nslog/comments.php on line 96

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.