Something I worked on over Easter was fixing up a script to set my key bindings dependent on whether or not my Apple keyboard is plugged in: the idea is that, on my laptop, this can be called on startup rather than me having to call it manually. I’ve now extended the script to detect whether or not my external monitor is plugged in using the excellent autorandr utility; I would have done this long ago but the non-free nvidia drivers screw up xrandr. So now I can just hit a key to fix things. The idea is that I will no longer have to reboot/restart X when leaving my desk etc. and this is made especially quick now that I have suspend on lip shut/open without a screen lock.

  #!/bin/sh

  # first fix keyboards

  if lsusb | grep -q "Aluminum Keyboard"; then
     dwm-applebindings &
  else
      setxkbmap -option ctrl:swapcaps
      setxkbmap -option "compose:ralt"
  fi

  # now sort out monitors
  auto-disper --change

  # finally fix stump mode-line
  stumpish eval "(enable-mode-line (current-screen) (current-head) nil)"
  stumpish fnext
  stumpish eval "(enable-mode-line (current-screen) (current-head) t)"
  stumpish fnext

And the xbindkeys config:

"/home/swhitton/bin/dwm-autobind"
  XF86Display

The Arch packages:

sudo clyde -S disper autorandr-git

You could have udev run the script automatically when the keyboard is plugged in; saves you a keystroke. I have udev set up to run a backup script when I plug in my backup disk.

% cat /etc/udev/rules.d/zz_backupdisk.rules
ACTION==”add”, ENV{ID_FS_UUID}==”2bfb8cf5-062c-4fda-b056-ed7d27a6f003”, RUN+=”/usr/local/sbin/auto_run_backup”

(There’s more than enough mediocre udev documentation on the web, of course)

Comment by t Tue 24 May 2011 16:00:30 UTC