From b747a5383f1f053404d4b3e7ede6da939f5b7e75 Mon Sep 17 00:00:00 2001 From: Maksim Okhotskii Date: Wed, 10 Aug 2022 10:02:35 +0300 Subject: [PATCH 1/2] Add pacmd set-sink wrapper module --- pacmd/__init__.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 pacmd/__init__.py diff --git a/pacmd/__init__.py b/pacmd/__init__.py new file mode 100644 index 00000000..e79951ac --- /dev/null +++ b/pacmd/__init__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +"""Sets default audio sink + + Synopsis: """ + +import subprocess +from albert import * + +__title__ = "Pulseaudio cmd" +__version__ = "0.1.0" +__triggers__ = "pacmd " +__authors__ = "c4pQ" +__exec_deps__ = ['pacmd'] + +iconPath = iconLookup('audio-headphones') + +def buildActions(): + pacmd_actions = [] + pacmd_output = subprocess.check_output(['pacmd', 'list-sinks']).splitlines() + sinks = [l[len('\t\tdevice.description = '):].decode() for l in pacmd_output if 'device.description' in str(l)] + for sink, i in zip(sinks, range(1, len(sinks) + 1)): + cl = ['pacmd', 'set-default-sink', str(i)] + pacmd_actions.append([i, sink, ProcAction(text=f'Set {sink} default', commandline=cl)]) + return pacmd_actions + +def handleQuery(query): + items = [] + if query.isValid and query.isTriggered: + actions = buildActions() + for action in actions: + items.append(Item( + id=f'pacmd-set-sink-{action[0]}', + icon=iconPath, + text=action[1], + subtext=f'Make {action[1]} default audio sink', + completion=action[1], + actions=[ action[2] ] + )) + return items From 365082f317467ebd3992fa9982c2f02f0317fefb Mon Sep 17 00:00:00 2001 From: Maksim Okhotskii Date: Tue, 18 Oct 2022 16:33:51 +0300 Subject: [PATCH 2/2] Follow up review comments --- pacmd/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pacmd/__init__.py b/pacmd/__init__.py index e79951ac..d9e61663 100644 --- a/pacmd/__init__.py +++ b/pacmd/__init__.py @@ -7,13 +7,13 @@ import subprocess from albert import * -__title__ = "Pulseaudio cmd" +__title__ = "Pulseaudio" __version__ = "0.1.0" -__triggers__ = "pacmd " +__triggers__ = "pa " __authors__ = "c4pQ" __exec_deps__ = ['pacmd'] -iconPath = iconLookup('audio-headphones') +iconPath = iconLookup('pulseaudio-text') def buildActions(): pacmd_actions = []