Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Open any URL from any app with Butler and AppleScript Apps
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.

[robg adds: This is a nifty script, and it worked as described, although I changed the tell application "Safari" bit to open Camino instead.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,610 views]  

Open any URL from any app with Butler and AppleScript | 11 comments | Create New Account
Click here to return to the 'Open any URL from any app with Butler and AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Open any URL from any app with Butler and AppleScript
Authored by: MtnBiker on Jun 07, '07 08:02:40AM

For some reason when I do this the box to type in (that box must have a name) is not in focus (I have to click in the box to be able to type, otherwise I'm still in the application I was in before I typed the shortcut). I put the script in Butler. Is this my set-up or the way Butler works?

If I make it an AS script and put in my Scripts folder, and I run the script from the Scripts Menu, the text fox comes up in focus.

I'd love to use this because it would save steps and it is fast.

I'm also going to change one of the buttons to Cancel because I have so (too) many shortcuts defined and I get the wrong one once in a while. Or is there another way to activate Cancel? "esc" doesn't work.

Second question: can Safari be changed to "default browser"? I sometimes change my default browser to Webkit or Firefox.

Thanks for posting this.

---
Hermosa Beach, CA USA



[ Reply to This | # ]
Open any URL from any app with Butler and AppleScript
Authored by: jdm on Jun 07, '07 04:03:39PM

If you wrap the display dialog in a "tell application" then the dialog will be brought to the front.

Here is my modification of the first couple of lines:

tell application "Finder"
display dialog "URL?" default answer "" buttons {"cancel", "open"} default button 2
set {text returned:theURL, button returned:okay} to result
end tell

if theURL is "" or okay is "cancel" then error number -128 -- cancel



[ Reply to This | # ]
Open any URL from any app with Butler and AppleScript
Authored by: dtomasch on Jun 07, '07 08:07:37PM
Add:
 

Tell Application "Butler"
activate
end tell

to the beginning, and it will bring the dialog box to front. dt

[ Reply to This | # ]
Open any URL with QuickSilver
Authored by: dbs on Jun 07, '07 08:33:52AM
Add a bookmark to safari:
Name: URL, URL: http://***/

Then refresh your QuickSilver list (or just wait for it to do it itself).

Type: command+space url tab cva.stanford.edu return

http://cva.stanford.edu/ will open in a new window in Safari.

No AppleScript needed, and it pops up a nice little window for entering whatever URL you want. I'm sure you can do the same thing with Butler.


[ Reply to This | # ]
Open any URL with QuickSilver
Authored by: morespace54 on Jun 07, '07 10:59:41AM
Or simply type : "stanford" once QS has be fired up.

If you already have the website in your bookmarks or have been on the website recently, the default browser will open http://cva.stanford.edu/ in a new window. I do believe that you might need to activate the Firefox/Mozilla or Safari modules for best results (regarding the browsers' history at least).

[ Reply to This | # ]
Open any URL with QuickSilver
Authored by: crashcane on Jun 07, '07 11:52:32AM
Is the "URL" bookmark even needed in this instance?

When I invoke Quicksilver, type "cva.stanford.edu" TAB, Quicksilver has autodetected that the text I typed is a URL, so the default Action is "Open URL", which opens the URL in my default browser.

When I type "w", "open URL" switches to "Open URL with...", and the third pane appears so I can select Safari, Camino, Firefox, Opera, etc.

If this isn't what happens in your install of Quicksilver, I would like to hear about it. One advantage/disadvantage of Quicksilver is that it does a ton of stuff "magically", but it is often hard to guess what it will do. For instance, I was trying to use Triggers to paste in commonly used text snippets, but with snippets that looked like URLs (stuff.foo.edu), which QS would autodetect as URL and "helpfully" paste in an "http://"; as well.

[ Reply to This | # ]
Open any URL with QuickSilver
Authored by: M.F. on Jun 08, '07 06:58:53AM

If you bring up quicksilver and hit the period button (.), the input area changes to a text editing field. Type any url there, and the default action will be to go to that website.



[ Reply to This | # ]
Open any URL with QuickSilver
Authored by: Skurfer on Jun 08, '07 09:12:33AM

Or you can tell Quicksilver (in the "Command" part of the Preferences) to automatically switch over to text mode if what you're typing doesn't match anything in the catalog. So if you type the address of a site you've never been to, it will automatically switch to text mode and automatically recognize the text as a URL, so the steps are:

  1. Invoke Quicksilver
  2. Type address
  3. Hit Return

…or you can do that complicated crap with creating shortcuts and writing Applescript and typing a lot of stuff to invoke it. ;)



[ Reply to This | # ]
Open any URL from any app with Butler and AppleScript
Authored by: jonn8n on Jun 07, '07 10:06:49AM
Can we please stop using AppleScripts to open web URLs that target specific browsers? Simply use the "open location" command and the URL will be opened in the default browser:
set the_url to "http://www.apple.com"
open location the_url
This command has been available for years and it also works for non-web URLs. For instance:
set the_url to "mailto:steve@apple.com"
open location the_url
or
set the_url to "file:///Applications/"
open location the_url
Jon

[ Reply to This | # ]
Web searches with Quicksilver
Authored by: Slinkwyde on Jun 07, '07 10:39:30AM

Quicksilver can also do web searches from any app via a hotkey activated interface. It's not just a Butler thing.

As someone who has used each for extended periods of time (Butler longer than Quicksilver), I can say that Butler is easier to grasp initially, but Quicksilver is a lot more powerful once you actually take the time to learn it in depth and start using the plugins. Many of the things that require using an AppleScript to accomplish with Butler don't require one with Quicksilver, and as a result Quicksilver is much more dynamic.



[ Reply to This | # ]
Open any URL from any app with Butler and AppleScript
Authored by: dtomasch on Jun 07, '07 08:04:25PM

I submitted this tip. Yeah, quicksilver does have powerful features, but it's always seemed… sluggish to me. A was also never able to figure out the same feature that Butler has—which is the opening of a small bezel-like dialog box, which pipes your input directly to a search engine. If there is a way to do that with Quicksilver, I'd probably go for it.



[ Reply to This | # ]