0

i own a Thinkpad yoga. This model has only function keys for increase or decrease the backlight. Minimum backlight does not switch the backlight completely off. So i use xbacklight to set the backlight to 0 percent. I made a shortcut on two unused functionkeys to turn the backlight to 0 and 50 percent. Now i want to merge these two functions in one key.

My idea about it:

read the value of the value, that xbacklight gives me, when its 0 then switch the backlight to a specific percentage, else, turn it to 0 (on and off)

I tried to write a script, but all my tries to save the output of the xbacklight command in a variable failed.

Thanks in advance!

#!/bin/bash

backlight= <-- in this variable i want to save the output of the xbacklight command 
if [ $backlight == 0 ];
then
xbacklight -set 50
else
xbacklight -set 0
fi

1 Answers1

2

Try this. You capture command output in a variable by using Bash's command substitution syntax $( ). To compare integer values, you also use -eq instead of ==.

#!/bin/bash

backlight=$(xbacklight -get)
if [ $backlight -eq 0 ]; then
    xbacklight -set 50
else
    xbacklight -set 0
fi
Byte Commander
  • 107,489
  • If this answer solved your problem, please consider accepting it by clicking the grey check button on its left. You should also read our small [tour] page to learn the basics about how this site works. Thanks and welcome to Ask Ubuntu. – Byte Commander Sep 20 '16 at 17:35