dotfiles/duskwm/.config/dusk/status_scripts/scripts/get_volume.py

27 lines
651 B
Python

import subprocess
from duskwm_logging import log
from theme import current_theme, default
data = subprocess.run(
["wpctl", "get-volume", "@DEFAULT_AUDIO_SINK@"],
stdout=subprocess.PIPE,
encoding="utf-8",
).stdout.strip()
try:
_, decimal, *muted = data.split(" ")
except Exception:
log.warning(data)
decimal = "0.0"
muted = "[MUTED]"
decimal = float(decimal)
muted = muted[0] if muted else ""
icon = "󰝟" if muted == "[MUTED]" else "󰕾"
color = (
f"^c{current_theme.base7}^" if muted == "[MUTED]" else f"^c{current_theme.base8}^"
)
vol_string = f"{decimal:.0%}"
content = f"^v^{color}{icon} {vol_string:>4}^t^"