"Close Tabs to the Right" with Safari
I've recently switched my "daily driver" for web surfing to Safari on my Mac. For one, well, it's just way faster. It might be that I have few extensions on it (mostly just LastPass), but I think it's also just generally pretty zippy. I found that Firefox weighs itself down after about 8 tabs, and while I'm definitely not a tab hoarder, sometimes my tabs can get upwards of around 15 when I'm doing research.
I still use Chrome as my primary development browser, because its Dev Tools are nicer, but it too suffers from a bloated, slow feeling when surfing.
But there's definitely one thing I missed, and that's "Close tabs to the right" (think of the "research mode" mentioned above, where I google something, open 5 different answers in a new tab, and then when I'm done with them, I need to close them).
Fortunately, we can fix this with Automator.
- Open Automator on your Mac, and create a new "service."
- For actions to run, choose "Run AppleScript," and enter the following AppleScript:
(which I thieved from this blog post.)
- Once you have that, save it - I named mine "close-right" (and I saved it to my iCloud, but I think you can put it anywhere).
- Now, one option is to show the script editor dropdown in your toolbar, and choose the script from there, but I've already got enough stuff there, so I'm just going to set up a keyboard shortcut for it instead. Open up "System Preferences" on your Mac, then pick "Keyboard."
- Here, you should select "App Shortcuts" and add a new shortcut for the "Safari" application. When asked about the menu item, you need to use the exact text that appears under Safari > Services for your new service (it should be the filename, like "close-right").
- Assign a keyboard shortcut (I used Command-Shift-Z).
- Now in Safari, when you press Command-Shift-Z, it closes tabs to the right of the one you're looking at!