-
-
Save nicodebo/297c1e134256ea24abf02a485ce41420 to your computer and use it in GitHub Desktop.
waybar, display brightness value of external screen using ddcutil
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
"custom/ddcutil": { | |
"format": "{percentage}% {icon}", | |
"interval": 1, | |
"format-icons": ["", "", ""], | |
"exec": "/path/to/waybar-ddcutil.py", | |
"return-type": "json" | |
}, |
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
#custom-ddcutil { | |
background-color: #f1c40f; | |
color: #000000; | |
} |
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 python | |
import subprocess | |
import json | |
data = {} | |
cmd = ["ddcutil", "getvcp", "10", "--bus", "1"] | |
value = subprocess.run(cmd, stdout=subprocess.PIPE).stdout.decode('utf8') | |
# output looks like this in my case: VCP code 0x10 (Brightness ): current value = 20, max value = 100 | |
percentage = value.split(":")[1].split(",")[0].split("=")[1].strip(" ") | |
data['percentage'] = int(percentage) | |
print(json.dumps(data)) |
Author
nicodebo
commented
Feb 26, 2021
Here is my implementation of the script, I am caching the value because many times when changing the brightness ddcutil wouldn't be able to get the value so it would break for a second and look really janky.
#!/bin/bash
output=$(ddcutil -t getvcp 10 2>/dev/null)
if [ $? -eq 0 ]; then
trimmed=${output#* * * }
value=${trimmed%% *}
cached_value=$(cat /tmp/waybar_ddcutil_value 2>/dev/null)
if [ "$cached_value" != "$value" ]; then
echo $value > /tmp/waybar_ddcutil_value
fi
echo {\"percentage\": $value}
else
echo {\"percentage\": $(cat /tmp/waybar_ddcutil_value 2>/dev/null || echo 0)}
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment