You are not logged in.

#1 2018-12-17 12:24:25

bheadmaster
Member
Registered: 2017-10-27
Posts: 43

xbacklight alternative shell script

I found a similar script on some archwiki discussion page long time ago, but I've improved it since, added a "fade" effect, although a little hacky.
Thought I'd share it. All feedback and criticism welcome.


#!/bin/sh

LOCK_DIR="/tmp/.brightnessctl.exclusivelock"
FILE_DIR="/sys/class/backlight/intel_backlight/"
FILE_NAME="brightness"
MAX_FILE_NAME="max_brightness"

change_brightness() {
	max_brightness=$(cat "${FILE_DIR}${MAX_FILE_NAME}")
	old_brightness=$(cat "${FILE_DIR}${FILE_NAME}")
	operand=$(echo "$1" | cut -c 2-)
	operator=$(echo "$1" | cut -c 1)

	i=1
	while [ "$i" -le "$operand" ]; do
		new_brightness=$(expr $old_brightness $operator $i)

		if [ $new_brightness -lt 0 ] \
				| [ $new_brightness -gt $max_brightness ]; then
			exit
		else
			echo $new_brightness > "${FILE_DIR}${FILE_NAME}"
		fi

		i=$(expr $i + 1)
	done

	return
}

if [ $(id -u) -ne "0" ]; then
	echo "Please run as root."
	exit
fi

#
# Use mkdir as an atomic operation to avoid multiple scripts running at once
#
if mkdir "$LOCK_DIR"; then

	case "$1" in
		[+-][0-9]*)
			change_brightness "$1" ;;
		*)
			echo "Invalid parameters [+|-][0-9]*"
	esac

	rmdir "$LOCK_DIR"
fi

.............|
............/  GNU
........../
__---'''             o  LINUX

Offline

Board footer

Powered by FluxBB