-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggleOutputDevices.py
47 lines (31 loc) · 1.05 KB
/
toggleOutputDevices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import comtypes
import soundcard as sc
import configparser, os
import policyconfig as pc
def switchSpeaker(switchTo):
policy_config = comtypes.CoCreateInstance(
pc.CLSID_PolicyConfigClient,
pc.IPolicyConfig,
comtypes.CLSCTX_ALL
)
policy_config.SetDefaultEndpoint(switchTo.id, pc.ERole.eMultimedia)
def setupCFG(cfg):
if os.path.exists('config-default.ini'):
with open('config-default.ini') as f:
cfg.read_file(f)
cfg.read('config.ini')
print([x.name for x in sc.all_speakers()])
CFG = configparser.ConfigParser()
setupCFG(CFG)
print(sc.default_speaker())
mainSpeaker = CFG['AUTOTURNOFF']['SPEAKERTOMONITOR']
SPEAKERIFOFF = CFG['AUTOTURNOFF']['SPEAKERIFOFF']
if mainSpeaker not in sc.default_speaker().name:
switchTo = next(x for x in sc.all_speakers() if mainSpeaker in x.name)
print(switchTo.id)
switchSpeaker(switchTo)
else:
switchTo = next(x for x in sc.all_speakers() if SPEAKERIFOFF in x.name)
print(switchTo.id)
switchSpeaker(switchTo)
print(sc.default_speaker())