OS X Sierra + VirtualBox + Hammerspoon
I prefer different modifier keybindings for my VM vs. native OS X, but VirtualBox (unlike VMWare/Parallels) passes the keyboard through to the VM natively without the ability to remap it on the way through.
Apparently one would normally use Karabiner to do all manner of trickery to remap keys per application etc. but support for this utility was broken in OS X Sierra. Instead, I use a pair of scripts:
switch.shuses the built-in
hidutilon OS X to remap modifier keys immediately when invoked
init.luais a lua script run by Hammerspoon that subscribes to window switching events and calls
switch.shif it finds the VM window.
switch.sh remap specifically?
In OS X:
- Caps Lock -> Command
In the VM:
- Caps Lock -> Control
- Command -> Alt
- Alt -> Command
Why not use XYZ?
Because it doesn't work under this very specific set of conditions for this very specific set of problems.