Using Butler to Key-Command URL

One of my favorite productivity apps is Butler. While the “Which launcher app is better?” debate will rage interminably, I especially like Butler’s ability to perform web searches simply via a keyboard shortcut activated pop-up bezel interface. All I have do to is hit Command-Option-Control-G, and a bezel box opens, allowing me to perform a Google search no matter what app I’m in. Ditto for -M and Google maps, -V and Version Tracker, etc.

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s