Big Cat (secure) 'Copy to public_html' | Main | It Even Went Underwater

August 16, 2004

Big Cat 'Build a Glossary Entry from Selection'

Posted by Mike on August 16, 2004 12:56 PM

Part of the job involves making sure that every article I run includes links to Webopedia definitions for each technical term the author uses.

Using BigCat, I've written a script that borrows from the basic "search for selection in Google" and expands it to include "search for selection in Webopedia, allow the user to accept the resulting URL, and add a pre-formatted entry to the glossary and the clipboard."

Next up is adding a simple looping script to add the code for definitions automatically when a word I've already looked up and glossarized is in a given document.

I'm posting these things here, by the way, less because I imagine there's someone else out there who has the same job as me, uses the same software as me and deals with the same problems as me, and more because, well, you never know who will find what useful. And I'm definitely benefitting from other people's scripting knowledge as I put these together. Seems the best way to give back.

--Open this script in a new Script Editor window.

on main(s)
    -- Webopedia's sort of a pain: no transparent search URL, but it does seem to be smart about redirecting "/foo.html" to the appropriate entry, so we'll bank on that:
    set baseurl to "" & s & ".html"
    open location baseurl
    --If jimmying the search works, offer a chance to add it to the glossary. On cancel, the script will die.
    display dialog "Add this to the BBEdit Glossary?"
    -- On ok, make OmniWeb give us its frontmost URL (which we just opened with the "open location baseurl" command
    tell application "OmniWeb"
        set theFrontmostWindowID to item 1 of (ListWindows)
        set theFrontmostWindowInfo to (GetWindowInfo theFrontmostWindowID)
        set myURL to item 1 of theFrontmostWindowInfo
    end tell
    -- make the URL into a properly formatted parenthetical "define" URL
    set the clipboard to " (<a href='" & myURL & "'>define</a>) " as string
    -- open up BBEdit
    tell application "BBEdit"
        --point glossFolder at the Glossary/Webopedia folder
        set glossFolder to "Macintosh HD:Applications:BBEdit 7.1:BBEdit Support:Glossary:Webopedia:"
        --set the name of the new document to the selection used to search
        make new text document with properties {name:s}
        -- file reference thingummer because AppleScript doesn't seem to like to address teh file directly
        set myfile to a reference to file (glossFolder & s)
        -- paste the newly created URL into the new document
        --save the newly created glossary file
        save front document to myfile
        close front document
    end tell
end main