Fn Brightness keys don'twork, Script+Bindkeys

So I have written the following script, however, I am a beginning programmer, thus, I know there's a (hopefully) better way than these ugly switches I have going on here... Any suggestions? I'm using passwordless sudo to change the brightness and binding the script to meta+f7 meta+f8 because fn+[f7,f8] doesn't report anything in freebsd, oddly enough (though it does in linux, and even opensolaris). Thanks in advance

Code:
#!/bin/csh
# lcd0 brightness
# hw.acpi.video.lcd0.levels: 100 48 19 24 29 34 39 48 55 61 71 80 100

set brightness = `sysctl -n hw.acpi.video.lcd0.brightness`
if ( "X$brightness" == "X" ) then
	echo "Error retrieving hw.acpi.video.lcd0.brightness sysctl."
	echo "Please ensure the acpi_video module is loaded,"
	echo "Run kldload acpi_video."
else
switch ($1)
	case down:
		switch ($brightness)
			case 19:
				sysctl hw.acpi.video.lcd0.brightness
				breaksw
			case 24:
				sudo sysctl hw.acpi.video.lcd0.brightness=19
				breaksw
			case 29:
				sudo sysctl hw.acpi.video.lcd0.brightness=24
				breaksw
			case 34:
				sudo sysctl hw.acpi.video.lcd0.brightness=29
				breaksw
			case 39:
				sudo sysctl hw.acpi.video.lcd0.brightness=34
				breaksw
			case 48:
				sudo sysctl hw.acpi.video.lcd0.brightness=39
				breaksw
			case 55:
				sudo sysctl hw.acpi.video.lcd0.brightness=48
				breaksw
			case 61:
				sudo sysctl hw.acpi.video.lcd0.brightness=55
				breaksw
			case 71:
				sudo sysctl hw.acpi.video.lcd0.brightness=61
				breaksw
			case 80:
				sudo sysctl hw.acpi.video.lcd0.brightness=71
				breaksw
			case 100:
				sudo sysctl hw.acpi.video.lcd0.brightness=80
				breaksw
			default:
				breaksw
		endsw
	breaksw
	case up:
		# increase lcd0 brightness
		# hw.acpi.video.lcd0.levels: 100 48 19 24 29 34 39 48 55 61 71 80 100
		switch ($brightness)
			case 19:
				sudo sysctl hw.acpi.video.lcd0.brightness=24
				breaksw
			case 24:
				sudo sysctl hw.acpi.video.lcd0.brightness=29
				breaksw
			case 29:
				sudo sysctl hw.acpi.video.lcd0.brightness=34
				breaksw
			case 34:
				sudo sysctl hw.acpi.video.lcd0.brightness=39
				breaksw
			case 39:
				sudo sysctl hw.acpi.video.lcd0.brightness=48
				breaksw
			case 48:
				sudo sysctl hw.acpi.video.lcd0.brightness=55
				breaksw
			case 55:
				sudo sysctl hw.acpi.video.lcd0.brightness=61
				breaksw
			case 61:
				sudo sysctl hw.acpi.video.lcd0.brightness=71
				breaksw
			case 71:
				sudo sysctl hw.acpi.video.lcd0.brightness=80
				breaksw
			case 80:
				sudo sysctl hw.acpi.video.lcd0.brightness=100
				breaksw
			case 100:
				sysctl hw.acpi.video.lcd0.brightness
				breaksw
			default:
				breaksw
		endsw
	breaksw	
	default:
		echo "No arguments given. Usage: brightness [up | down]"
	breaksw
endsw
endif

P.S. some of this is unnecessary. but I did it to learn! :stud
 
Oh, and also... In that first part of the script where it says "Error retrieving sysctl value for hw.acpi.video.lcd0.brightness, please ensure acpi_video is kldloaded..." If acpi_video isn't loaded, this causes sysctl to give an error. This error is also shown when running the script. Is it possible to mask the output of this command when running the script? I havent found any good cshell or sh scripting tutorials in the internet, i did buy a bash scripting book, however, but its very linux-centric.
 
So like
Code:
$brightness=`sysctl -n hw.acpi.video.lcd0.brightness >&`
or
Code:
$brightness=`sysctl -n hw.acpi.video.lcd0.brightness 2>& /dev/null`
or
Code:
$brightness=`sysctl ... >& /dev/null`
or
Code:
$brightness=`sysctl ... 2>&`

Also, I've tried to find good online resources for these things, if anyone can recommend where to find such information it would be greatly appreciated.
 
The third one.

Code:
some_command >&/dev/null

I rarely script in csh, but from what I know, csh can only redirect stdout >, or redirect stdout and stderr >&. You can't redirect stderr alone. But you can use parentheses to filter stderr from stdout.

Code:
(some_command > /dev/tty) >&/dev/null


Example:

Code:
#a file named abc that contains the word 'stdout' ; stderr is not a valid command
root@meh:~#( more abc ; stderr ) 
stdout
stderr: Command not found.

#redirect stdout and stderr to /dev/null
root@meh:~#( more abc ; stderr ) >&/dev/null
root@meh:~#

#redirect stdout to /dev/tty, stderr will be caught by /dev/null
root@meh:~#( more abc > /dev/tty; stderr ) >& /dev/null
stdout

#stdout will be caught by /dev/null, stderr goes to /dev/tty but then caught by /dev/null
root@meh:~#( more abc ; stderr > /dev/tty ) >& /dev/null
root@meh:~#


HTH.
 
Back
Top