!7 cmodule AudioAdjuster > DynPrintLogAndEnabled { transient S goodMic = "USB PnP Audio Device Analog Stereo"; transient S headphones = "Bluedio T 5th"; //"Bluedio T"; transient S internal = "HD-Audio Generic Analog Stereo"; transient S defaultSink; transient Bool haveGoodMic, haveHeadphones; transient long lastChecked; start { doEvery(10.0, r check); dm_registerAs_direct haveHeadphones(); } void check enter { if (!enabled) ret; lastChecked = now(); Map sinks = dm_systemAudioSinkNames(); bool haveGoodMic = cicValue(sinks, goodMic); bool haveHeadphones = cicValue(sinks, headphones); S defaultSink = haveHeadphones ? headphones : internal; if (setFields(+defaultSink, +haveGoodMic, +haveHeadphones)) dm_pulseAudio_setDefaultSinkAndSwitchAllClients(defaultSink); } // API WithTimestamp haveHeadphones() { ret withTimestamp(lastChecked, haveHeadphones); } }