URL link bbcoder for the bbs.

Remember - this script expects to find the url you want inserted in the clipboard, and the text you want to use as a bbcoded link highlighted in a browser text box. It will replace the text with a full-blown URL link like this:

This is a link to Google formed like this:

[url=http://www.google.com]Google[/url]
-- This script starts with a URL in the clipboard and a link script highlighted in a forum's text window in a browser. 
-- It cuts the link script and forms a bbcode url from it. Be careful with spaces in the selection.
set theURL to the clipboard -- we're going to use the clipboard again!
tell application "Finder"
    set visible of process "Script Editor" to false -- Needed if run is clicked in the Script Editor. If a compiled app is double-clicked put its name in place of "Script Editor" (no extension). Comment this line out if the script is run by a key command to a hotkey application like QuicKeys or FastScripts.
    set Front_App to item 1 of (get name of processes whose frontmost is true) -- this should be the browser
end tell

tell application Front_App to activate -- necessary if you've just hidden the Script Editor or your script.app
tell application "System Events"
    tell process Front_App
        keystroke "x" using {command down} -- cut the link phrase.
        keystroke "[url= & theURL & ]" -- stick in the bbcoded url.
        keystroke (the clipboard) -- put the link text back.
        keystroke "[/url]" -- close the bbcode
    end tell
end tell