Scrawls from Preston...

Powered by Pelican.

Fri 26 September 2014

Tab tool hack

If you are like me, you often have waaaay too many tabs open.

Too often I know I have some tab open somewhere, and get frustrated clicking through too many windows to find it. I probably should be better and more discriminating about opening so many, but instead I'll write a little hack to help me out.

This is a little tool that works on Mac for Safari and Chrome.

Given this is just a quick hack I'm going to cover quick setup without explaining all the pieces - if you have a typical Python hacker setup, should be pretty straightforward.

It uses Python and Appscript to get browser info. I'm assuming you use virtualenv and virtualenv wrapper.:

cd /usr/local/bin
curl -O
curl -O
chmod +x stab ctab
mkvirtualenv appscript
pip install appscript
which python | pbcopy

You now have the path to the appscript aware python on your clipboard.

edit the shebang at the top of /usr/local/bin/stab

Now to use it, you can use stab for Safari and ctab for Chrome


stab # lists tabs

# activates tab 34 from the list
stab 34

# activates first tab whose name matches pattern 'foobar' (regex, ignorecase)
stab foobar

# lists tabs with foo in the name, because I already have ack installed
stab | ack foo

Now go open some more tabs...