#!/bin/bash # A script to manage screen and keyboard brightness on my machine # Depends on: bash, brightnessctl # By David Penkowoj, 2021/06/24 MTR_DEVICE="amdgpu_bl2" MTR_VALUE=46 SWITCH="$1" case $SWITCH in "help") printf "Possible arguments:\n" printf "===================\n" printf "load - loads brightness from save\n" printf "save - saves current brightness\n" printf "up - increases brightness by 5 percent and saves\n" printf "down - decreases brightness by 5 percent and saves\n" printf "smallup - increases brightness by 1 percent and saves\n" printf "smalldown - decreases brightness by 1 percent and saves\n" printf "status - show brightness of a device" ;; "load") brightnessctl --device="$MTR_DEVICE" set "$MTR_VALUE%" ;; "save") M="$(brightnessctl --device="$MTR_DEVICE" | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)" sed -i "s/MTR_VALUE=$MTR_VALUE/MTR_VALUE=$M/" "$0" ;; "smalldown") if [[ "$2" = "monitor" ]]; then brightnessctl --device="$MTR_DEVICE" set 1-%; fi brightness save notify-send -u low -r "110" "$2: $(brightness get monitor)" ;; "smallup") if [[ "$2" = "monitor" ]]; then brightnessctl --device="$MTR_DEVICE" set +1%; fi brightness save notify-send -u low -r "110" "$2: $(brightness get monitor)" ;; "down") if [[ "$2" = "monitor" ]]; then brightnessctl --device="$MTR_DEVICE" set 5-%; fi brightness save notify-send -u low -r "110" "$2: $(brightness get monitor)" ;; "up") if [[ "$2" = "monitor" ]]; then brightnessctl --device="$MTR_DEVICE" set +5%; fi brightness save notify-send -u low -r "110" "$2: $(brightness get monitor)" ;; "get") M="$(brightnessctl --device="$MTR_DEVICE" | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)" if [[ "$2" = "monitor" ]]; then echo "$M"; fi ;; *) printf "Monitor:\n" brightnessctl --device="$MTR_DEVICE" | tail -n 3 | sed 's/\t/- /g' ;; esac