You may know this Mac/OSX feature: one plugs or unplugs an external audio-interfaces and the system automatically switches the sound to the new device. - It may not always be what you want, but it is an very handy feature especially for mobile systems. and here's how to set this up for JACK on GNU/Linux..

First, we need a mechanism to switch the “JACK backend” in order to switch between audio-interfaces. The task includes taking care of re-connecting physical I/O ports in case they're different on each device.

Second, said mechanism needs to be triggered automatically when a new device is connected or if a device goes away.
Here's a short annotated demo-video:

(If Flash is installed JavaScript is activated, you can watch a video inside this web page.)

(well yes, I should have ripped out that USB cord more visibly.. sorry, next time. I might use a real camera too, then.)

The two last are redundant and exclusive. JACKd still needs a patch to send a DeviceError. Using HAL's DeviceRemoved may be problematic for setups with more than two sound-cards if the removed device was not currently the one used by JACK.

Note that myjackctl.sh uses the org.jackaudio.PatchBay dbus-API which is broken in jack2-r4120 (see ticket below) and fixed by Nedko in jack2-r4366.

Future: Instead of patching jack2 to send additional messages (here: org.jackaudio.JackControl,member=DeviceError), the trigger functionality should be built into jackd, but requires a callback to the control API to be added to JACK.

The shell hook-script (myjackctl.sh) could be implemented easier and more flexible using python (jack-control API bindings) or similar language more suitable to parse and provide audio-port mapping and configuration.