Skip to content

Instantly share code, notes, and snippets.

@adamzwakk
Created October 30, 2018 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamzwakk/258dec8e78e25ff024d623bbe1062e92 to your computer and use it in GitHub Desktop.
Save adamzwakk/258dec8e78e25ff024d623bbe1062e92 to your computer and use it in GitHub Desktop.
control laptop backlight via xbacklight and send notification via libnotify
#!/bin/bash
# You can call this script like this:
# $./backlight.sh up
# $./backlight.sh down
function get_brightness {
cat /sys/class/backlight/intel_backlight/brightness;
}
function max_brightness {
cat /sys/class/backlight/intel_backlight/max_brightness;
}
function send_notification {
brightness=`get_brightness`
max_brightness=`max_brightness`
percent=$(echo "scale=2; ($brightness / $max_brightness)*100" | bc)
percent=${percent%.*}
echo $percent
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
bar=$(seq -s "─" $(($percent / 5)) | sed 's/[0-9]//g')
# Send the notification
notify-send "$percent% $bar" -t 5000 -r 1001
}
case $1 in
up)
xbacklight -inc 2
send_notification
;;
down)
xbacklight -dec 2
send_notification
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment