How to Open a New Safari Tab Next to the Current Tab, Instead of at the End of the Lot

John Gruber, on Daring Fireball, detailing how he got to change Safari’s behaviour to open new tabs next to the active tab:

If I have, say, 10 tabs open in a window and I’m currently using, say, tab 2, when I type ⌘T to open a new tab it feels like the rightmost end of the row of tabs is “way over there”, but what I want is the new tab to open “right next to where I am” — like what happens when I ⌘-click a link.

A few months ago I asked on Twitter if there was a secret preference in Safari that would change this to what I want — which is for new tabs to always open right next to the current tab. There is no such preference. I set about trying trying to figure out if this could be done using AppleScript, but I couldn’t figure it out.
Jeff Johnson figured it out, though, and was kind enough to share the solution and explain the rather ungainly syntax required.

John used FastScripts for this but I decided to try my luck with Keyboard Maestro…

This was extremely easy. I added a new macro to my Safari group (macros limited only to Safari), used ⌘T as the Hot Key trigger, which will override Safari’s action, and just pasted in John’s AppleScript:

tell application "Safari"
tell front window
set _old_tab to current tab
set _new_tab to make new tab at after _old_tab
set current tab to _new_tab
end tell
end tell

Works like a charm.