I also wanted to do swap cmd and alt keys only on my MacBook Pro, but not when I have a normal external keyboard plugged in.
From the directions here, the following "just works" on 14.04 (and likely 13.10):
- Add
options hid_apple swap_opt_cmd=1
to/etc/modprobe.d/hid_apple.conf
, creating the file if it doesn't exist - Rebuild initramfs with
sudo update-initramfs -u -k all
- Reboot