please tell us the distribution and version of "linux" you are using, and the desktop GUI too. thanks
This is sort of a clumsy way to do it but it works. The more elegant solution is to use udev rules to allow switching to the devices you want to automatically switch to while ignoring devices that you do not want to switch to. For example when I turn on my bluetooth headset, I want it to switch.