forked from alexlafroscia/alfred-switch-audio-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchAudioSource.py
49 lines (35 loc) · 1.04 KB
/
SwitchAudioSource.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
45
46
47
48
49
from subprocess import check_output, call
from json import dumps
from sys import stdout
from os import environ
PATH_TO_SWITCH_AUDIO_OUTPUT = environ['SWITCH_AUDIO_SOURCE_PATH']
LOOKUP_WARNING = "Error: Could not find SwitchAudioSource"
class AudioSource:
def __init__(self, description):
words = description.split(' ')
output = words.pop(-1)
title = ' '.join(words)
self.uid = title
self.title = title
self.arg = title
self.autocomplete = title
self.output = output.find('output') > -1
self.input = not self.output
def __str__(self):
return str(self.__dict__)
def get_sources():
command_output = check_output([
PATH_TO_SWITCH_AUDIO_OUTPUT, '-a'
])
return map(lambda line: AudioSource(line), command_output.splitlines())
def set_output(device):
call([
PATH_TO_SWITCH_AUDIO_OUTPUT, '-s', device
])
def no_path_provided():
stdout.write(dumps({
"items": [{
"title": LOOKUP_WARNING
}]
}))
exit()