dotfiles/laptop/.config/xmobar/scripts/volume.py

44 lines
802 B
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
import subprocess
USE_SYMBOLS = True
VOLUME_COMMAND = 'amixer get Master'.split(' ')
VOLUME_SYMBOLS = {
"0": "𝒫", # "∅"
"10": "",
"20": "=",
"30": "",
"40": "",
"50": "",
"60": "",
"70": "",
"80": "",
"90": "",
"100": "",
}
def get_volume():
volumeData = subprocess \
.check_output(VOLUME_COMMAND) \
.decode() \
.split('\n')[5] \
.strip() \
.split(' ')
volume_level = int(volumeData[-2][1:-2])
if USE_SYMBOLS:
volume = VOLUME_SYMBOLS[str((volume_level // 10) * 10)]
if volumeData[-1] == '[off]':
volume = 'Ψ'
else:
volume = f'{volume_level}%'
if volumeData[-1] == '[off]':
volume = 'M'
return volume
if __name__ == '__main__':
print(get_volume())