Plippo/asus-wmi-screenpad

Snippet: Script for brightness shortcut buttons on Linux 6.7+

AmazingGinger opened this issue · 0 comments

Script for shortcut buttons

I made this script. I call it with .local/asus-sp.sh up on the "Shift + brightness_up" button.

This does require a sudoers entry for wheel or adm

# visudo
%users ALL=(ALL) NOPASSWD: /bin/bash -c echo [0-9]* > /sys/class/backlight/asus_screenpad/brightness
%users ALL=(ALL) NOPASSWD: /bin/bash -c echo [0-1] > /sys/class/backlight/asus_screenpad/bl_power
#!/usr/bin/env bash
# .local/asus-sp.sh
INC=5 # Can be as low as 2

current_brightness_v=$(cat /sys/class/backlight/asus_screenpad/brightness)
max_brightness_v=$(cat /sys/class/backlight/asus_screenpad/max_brightness)
cutoff=$(( $INC * -1 + 1 ))

asus-sp-power() { # zero is on, 1 is off
  sudo bash -c "echo $1 > /sys/class/backlight/asus_screenpad/bl_power"
}

asus-sp() {
  if [[ $1 -ge 100 ]]; then
    asus-sp-power 0
    sudo bash -c "echo $max_brightness_v > /sys/class/backlight/asus_screenpad/brightness"
    echo "Brightness set to MAX. ($1)"
  elif [[ $1 -ge 0 && $1 -le 100 ]]; then
    asus-sp-power 0
    local brightness_v=$(( $1 * $max_brightness_v / 100 ))
    echo "Brightness set to $1%. ($brightness_v)"
    sudo bash -c "echo $brightness_v > /sys/class/backlight/asus_screenpad/brightness"
  elif [[ $1 -lt 0 && $1 -ge $cutoff ]]; then
    echo -e "\a"
    echo "Brightness set to MIN. ($1)"
  elif [[ $1 -lt 0 ]]; then
    asus-sp-power 1
    echo "Screenpad turned off. ($1)"
  else
    echo "Invalid brightness value: $1. Please specify a value between 0 and 100."
  fi
}

current_brightness=$(( ( $current_brightness_v * 100 ) / $max_brightness_v ))
if [ $1 == 'up' ]; then
  set_to=$(( $current_brightness + $INC ))
  echo "Setting to $set_to, from $current_brightness."
  asus-sp $set_to
elif [ $1 == 'down' ]; then
  set_to=$(( $current_brightness - $INC ))
  asus-sp $set_to
else
  echo "Pass 'up' or 'down' to change brightness by $INC."
fi

Screenshot from 2024-02-14 13-05-46