I use mutt with urlview to open urls in firefox. I just got fed up with firefox stealing focus when I open a link, since I'm still in email processing mode.
The canonical answer uses about:config to alter your firefox config to:
browser.tabs.loadDivertedInBackground = true
Well, that's great... when you like all urls loaded in the background. I like urls I clicked open in firefox to load in the background, and want urls I opened via other programs to load in the foreground.
So, let's steal focus back from firefox (that greedy pig deserves it).
#!/bin/sh # call firefox and switch back to our window # die() { echo $* ; exit 1 ; } window_before_firefox=$( xprop -root | awk '/^_NET_ACTIVE_WINDOW/ { if (match($0, "0x[0-9a-fA-F]+")) { print substr($0, RSTART, RLENGTH) }} ') /usr/bin/firefox $1 [ -z "${window_before_firefox}" ] && die "we don't know who we are. great." wmctrl -i -R ${window_before_firefox}