Make your own beautiful website today with Squarespace. Use DARING17 to get 10% off your first purchase.

Service: Open URLs in Safari Tabs

Tuesday, 3 August 2010

I’ve mentioned before that one of my favorite improvements to Snow Leopard was the overhaul of the system-wide Services menu. Service menu items are more easily accessed (including via the system-wide contextual menu), keyboard shortcuts are now easily configurable, and, best of all, you can easily create your own services using Automator and scripting languages like AppleScript, Perl, Ruby, and Python. Here’s a good overview of Snow Leopard services from Sal Soghoian.

I’ve written a bunch that I use personally. One of my most-used is called “Open URLs in Safari Tabs”. Here’s how it works:

Select some text in any application.

Invoke the Open URLs in Safari Tabs service. (I usually do this via the control-click contextual menu.

The service passes the selected text to a script I wrote. The script finds all the URLs in the selected text, opens a new Safari window, and creates a tab in that new window for each of the URLs.

The most common app from which I use it is Mail. Say someone sends me an email with three URLs, and I want to open all three of them. The typical way is to click one, which opens it in Safari and brings Safari to the front, then switch back to Mail and click the next one (which again brings Safari front), then switch back to Mail again and click the last one.1

With this service, I just select a range of text in the message that includes all three URLs, control-click on the selection, and select “Open URLs in Safari Tabs”.

I wrote the script so that Safari doesn’t come to the front when the service is invoked — the new window and tabs are created in the background. (If you’d rather have Safari come to the front, there’s a line in the script you can uncomment.)

Download and Installation

Move the file named “Open URLs in Safari Tabs.workflow” to the ~/Library/Services/ folder in your home folder. (If there is no “Services” folder in your Library folder, create it.)

The service should now be available system-wide, both via the contextual menu and the Services sub-menu in the Application menu, when the current selection is a range of text. You can set a keyboard shortcut for any service in the Keyboard panel of System Preferences. If you wish to examine how it works or change its behavior, open it using Automator.

Caveats

The service only works with Safari (and WebKit nightlies); it doesn’t work with other browsers such as Firefox or Chrome. The version I’ve made available for download requires Mac OS X 10.6 (Snow Leopard) or later; if you’re using 10.4 or 10.5, you can create a service based on the below-linked Perl script using Jesper’s free ThisService utility.