Source

BASH scripts / scripts / brightness.sh

#!/bin/bash
#
# vaio_progressivebright.sh
#
# Changes bright state progresively in Sony Vaio
#
# Praeter Feror <praeterferor@gmail.com>
# Version 2.0
#
# 2008-07-11

#MaxBright=100
#MinBright=0
#StepBright=10
MaxBright=8
MinBright=0
StepBright=1
#FILE="/sys/class/backlight/acpi_video0/brightness"
FILE="/sys/class/backlight/acpi_video0/brightness"
Current=`cat $FILE`

function show_usage {
echo "Usage: $(basename ${0}) <option>"
	echo "  up:   Increases bright"
	echo "  down: Decreases bright"
	echo "  cur:  Tells about current bright"
}

function bright_up {
	if [ $Current -lt $MaxBright ]; then
		Current=$(($Current+$StepBright))
		if [[ ${Current} -ge ${MaxBright} ]]; then
			Current=${MaxBright}
		fi
		echo "${Current}" > ${FILE}
		echo "Bright increased to: $Current"
	else
		Current=${MaxBright}
		echo "Bright is already to $MaxBright (max)"
	fi
}

function bright_down {
	if [ $Current -gt $MinBright ]; then
		Current=$(($Current-$StepBright))
		if [[ ${Current} -le ${MinBright} ]]; then
			Current=${MinBright}
		fi
		echo "${Current}" > ${FILE}
		echo "Bright decreased to: $Current"
	else
		Current=${MinBright}
		echo "Bright is already at $MinBright (min)"
	fi
}

#if [[ `whoami` != "root" ]] && [[ "${1}" != "cur" ]]
if [[ `whoami` != "root" ]] && ([[ "${1}" = "up" ]] || [[ "${1}" = "down" ]])
then
	echo "You must be root in order to run this script"
	exit 1
fi

if [ ${#} -ne 1 ]; then
	show_usage
	exit
else
	if [ ${1} == "up" ]; then
		bright_up
	elif [ ${1} == "down" ]; then
		bright_down
	elif [ ${1} == "cur" ]; then
		echo "Current bright: $Current"
	else
		show_usage
		exit 1
	fi
fi

exit 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.