Created
April 18, 2023 19:55
-
-
Save galister/7f11af9aa765ae4e17c46ce336cb5f85 to your computer and use it in GitHub Desktop.
Per-app volume adjustments for PW/Pulse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import subprocess | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) < 3: | |
print("Usage: %s <appname> <amount>" % sys.argv[0]) | |
raise SystemExit() | |
appname = sys.argv[1] | |
amount = sys.argv[2] | |
json_str = subprocess.check_output(["pactl", "-fjson", "list", "sink-inputs"]) | |
data = json.loads(json_str) | |
lastIndex = -1 | |
for node in data: | |
if node.get("properties", {}).get("node.name", "") == appname: | |
index = node.get("index", -1) | |
if lastIndex < index: | |
lastIndex = index | |
lastIndex = str(lastIndex) | |
subprocess.call(["pactl", "set-sink-input-volume", lastIndex, amount]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment