This code uses the AudioEndpoint plugin in a Python script. When the event triggers (currently by hotkey), the script finds the audio devices that correspond to my speakers and my Logitech headset, figures out which one is active, and switches to the other.
Why do it this way? My headset is USB-connected, and the ID that represents it in EventGhost was changing from time to time, breaking my action. Now the ID can be whatever it wants, as long as I name the audio device properly. In my Windows settings, I've named my speakers "Speakers" and my headset "Logitech headset", and this event just checks for names that start with one of those two.
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
<Macro Name="Audio device" XML_Guid="{BF169A5E-6DE2-481E-96A7-08929DF82E84}" Expanded="True">
<Event Name="Keyboard.Ctrl+Alt+M" XML_Guid="{C5FCABBA-4125-469C-A9D0-0806FBB0C93A}" />
<Action Name="Python Script: smart switch audio device" XML_Guid="{53DD2A2D-00C9-43F4-9EB6-B54C30889183}">
EventGhost.PythonScript(u'audioConsole = 0\naudioMultimedia = 1\n\naep = eg.plugins.AudioEndpoint.plugin\nddef = None\ndspk = None\ndear = None\nfor d in aep.AudioDevices:\n if d.isDefault():\n ddef = d\n if d.getName()[0:8] == "Speakers":\n dspk = d\n elif d.getName()[0:8] == "Logitech":\n dear = d\n\n\nif ddef == dspk:\n aep.AudioDevices.SetDefault(dear, audioConsole)\nelse:\n aep.AudioDevices.SetDefault(dspk, audioConsole)\n')
</Action>
</Macro>
</EventGhost>