Closer to fine

At $WORK I typically have three things open on my desktop:

  1. Firefox
  2. Emacs
  3. 4 x 10^8 xterms

I use Awesome as a window manager, and despite RSI (I keep tucking my thumb under my left hand to reach the Windows key) it has worked out okay for me. There's not a lot I need the mouse for, especially if I'm disciplined enough to keep the mouse far away from the keyboard.

However, there's one thing I need: cutting and pasting. When troubleshooting I take notes in Org/Emacs, often on a remote SSH/tmux session, and I need to cut-and-paste sixty different URLs from Firefox into my notes. (Still not quite hardcore enough to run w3m-mode regularly, which is a bit like saying "I only get drunk after 10am.") And for that, I have to reach for the mouse, which breaks flow, which makes baby Linus cry.

This xdotool script (Hey Jordan, I thought your site was supposed to be up by now!) comes very, very close to making that go away.

#!/bin/sh
# Activate firefox and copy the URL bar contents; also available with "xclip -o".  OMG.

# Get the current window and mouse location so we can come back
pwid=`xdotool getactivewindow`
eval $(xdotool getactivewindow getwindowgeometry --shell|grep -e X -e Y)
# Find and activate the FF window
wid=`xdotool search --name "Mozilla Firefox"`
xdotool windowactivate $wid
sleep 0.2
# Go to location bar, select all, and cut
xdotool key "ctrl+l"
xdotool key "ctrl+a"
xdotool key "ctrl+c"
sleep 0.2

# Go back, move the mouse a bit, and middle-click to paste
xdotool windowactivate $pwid
xdotool mousemove $(( X + 50 )) $(( Y + 50 ))
sleep 0.2
xdotool click 2

It is a trifle flaky: it works in some environments (xterm+emacs shell) but not others (xterm w/SSH/tmux/emacs). Of course, that's just after a few minutes playing around, and I may need to look for help from wmcrtl. But oh, that's nice. Thanks, Jordan.