aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/bar/brightness
blob: da28db3441477c23b0a23258aba46c955ab45ce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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="$MTR_DEVICE"
MTR_DEVICE="intel_backlight"
KBD_DEVICE="smc::kbd_backlight"
MTR_VALUE=49
KBD_VALUE=

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%"
    brightnessctl --device="$KBD_DEVICE" set 0 # "$KBD_VALUE%"
    ;;
  "save")
    M="$(brightnessctl --device="$MTR_DEVICE" | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)"
    K="$(brightnessctl --device="$KBD_DEVICE" | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)"
    sed -i "s/MTR_VALUE=49$MTR_VALUE/MTR_VALUE=49$M/g" "$0"
    sed -i "s/KBD_VALUE=$KBD_VALUE/KBD_VALUE=$K/g" "$0"
    ;;
  "smalldown")
    if [[ "$2" = "monitor" ]]; then brightnessctl --device="$MTR_DEVICE" set 1-%; fi
    if [[ "$2" = "keyboard" ]]; then brightnessctl --device="$KBD_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
    if [[ "$2" = "keyboard" ]]; then brightnessctl --device="$KBD_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
    if [[ "$2" = "keyboard" ]]; then brightnessctl --device="$KBD_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
    if [[ "$2" = "keyboard" ]]; then brightnessctl --device="$KBD_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)"
    K="$(brightnessctl --device="$KBD_DEVICE" | grep -Eo "[0-9]+" | head -n 2 | tail -n 1)"
    if [[ "$2" = "monitor" ]]; then echo "$M%"; fi
    if [[ "$2" = "keyboard" ]]; then echo "$K%"; fi
    ;;
  *)
    printf "Monitor:\n"
    brightnessctl --device="$MTR_DEVICE" | tail -n 3 | sed 's/\t/- /g'
    printf "Keyboard:\n"
    brightnessctl --device="$KBD_DEVICE" | tail -n 3 | sed 's/\t/- /g'
    ;;
esac