Jun 07, '07 07:30:03AM • Contributed by: Anonymous
I found myself wanting the ability to assign a simple keyboard shortcut, get a dialog box, and open any URL I wanted -- no reaching for my browser. While Butler contains a way to do this, it generally requires a step or two more than I'd like, and I wanted a more direct solution. Using one of Butler's most powerful features -- the ability to execute any AppleScript code with only a keyboard shortcut -- I implemented the following code:
display dialog "URL?" default answer "" buttons {".net", ".org", ".com"} default button 3
set {text returned:theURL, button returned:theDomain} to result
if theURL is "" then error number -128 -- cancel
if (offset of "." in theURL) is 0 then
-- This works for other domains, as long as no subdomains are entered
set theURL to theURL & theDomain
end if
if theURL starts with "www." then
set theURL to "http://" & theURL
else if theURL does not start with "http://www." then
set theURL to "http://www." & theURL
end if
tell application "Safari"
activate
open location theURL
end tell(With a little revision from our friends at macscripter.net)
I've assigned this to the key combination Command-Option-Control-U, and now I can open a URL no matter what application I'm in or what I'm doing -- and with almost no attention necessary to the prefix or suffix.
[robg adds: This is a nifty script, and it worked as described, although I changed the tell application "Safari" bit to open Camino instead.]
