Close tabs to the right for Safari

Chrome has a terrific feature that lets you close all the tabs to the right of the current one. Very handy if you’ve opened a bunch of links from search results, found the one you want, and want to get rid of all the rest. Safari is a bit more limited; you can only close all but the current tab. You can get around that via Applescript.

First, make sure “Show Script menu in menu bar” is checked in the Applescript Editor preferences. Enter the following script into Applescript Editor, and save it to ~/Library/Scripts/Applications/Safari.

tell window 1 of application "Safari"
    close (tabs where index > (get index of current tab))

If you wanted to be able to assign a keyboard shortcut for this, you can turn the script into a service using ThisService, and assign the shortcut in the Keyboard Preferences Pane.

(via Ask Different)

Use DNS prefetching to speed up web font loading

Poking around in a framework today, I saw they’d suggested using the new dns-prefetching feature in HTML5 to speed up resolving some foreign domains. Further digging showed folks are prefetching the domains from which Google serve their web fonts. It’s a great idea, given that web fonts are one of the biggest contributors to page weight on a largely text web site.

To include prefetching of the Google web fonts domains in your page, add the following code to your head:

<link rel="dns-prefetch" href="//">
<link rel="dns-prefetch" href="//">

Change DNS servers from the command line in Mac OS X

Changing DNS servers isn’t something most people need to do frequently. When you do need to change them up, though, it takes too many clicks in System Preferences. Use networksetup at the command line instead. For example, to change your DNS server to the OpenDNS servers, issue the following (if you’re using Ethernet):

sudo networksetup -setdnsservers Ethernet

To get a list of all the network services you could be using, run

networksetup -listallnetworkservices

If you make a lot of changes to your network throughout the day, it’s worth getting to know what networksetup can do. And don’t forget that any command you can run in a shell can be incorporated into an AppleScript or Automator workflow with do shell script.