import shutil import subprocess def set_volume(value: int): value = max(0, min(100, value)) if shutil.which("wpctl"): _run_cmd(["wpctl", "set-volume", "@DEFAULT_AUDIO_SINK@", f"{value}%"]) return if shutil.which("amixer"): _run_cmd(["amixer", "sset", "PCM", f"{value}%"]) def _run_cmd(args: list[str]): try: subprocess.run( args, capture_output=True, text=True, timeout=1, check=False, ) except (OSError, subprocess.SubprocessError): pass