Ubuntu 调节亮度快捷键修复

2018-01-07  本文已影响0人  lomot

由于ubuntu的驱动问题,笔记本上的亮度调节快捷键基本上用不了,所以我写了个脚本来调节亮度,然后把脚本映射到自定义快捷键上

原理

控制亮度文件的文件在
/sys/class/backlight/intel_backlight/brightness里面

$ cd /sys/class/backlight/intel_backlight

$ ls
actual_brightness  brightness  max_brightness  subsystem  uevent
bl_power           device      power           type

$ cat brightness 
287

$ cat max_brightness 
937

brightness里面保存的是当前亮度
max_brightness里面保存的是亮度最大值
所以直接修改brightness的值就可以调节亮度了

开始操作

首先修改brightness的权限

sudo chmod 777 /sys/class/backlight/intel_backlight/brightness

然后可以执行命令测试是否能调节亮度

调节亮度为100
echo 100 > /sys/class/backlight/intel_backlight/brightnes
调节亮度为0
echo 0 > /sys/class/backlight/intel_backlight/brightnes

如果成功了就可以开始写脚本了


亮度增加 :brightness_up.sh

#password里面填你的密码
if [ ! -w /sys/class/backlight/intel_backlight/brightness ];then 
    echo "password" | sudo -S chmod 777 /sys/class/backlight/intel_backlight/brightness 
fi 

read bright < '/sys/class/backlight/intel_backlight/brightness' 
 
v=0
v=$((30 + $bright)) 
 
if [ $v -gt 937 ]; then 
    v=937 
# 937为我的最大亮度,即max_brightness文件里面的值
fi 
 
echo $v > /sys/class/backlight/intel_backlight/brightness 

亮度降低 :brightness_down.sh

if [ ! -w /sys/class/backlight/intel_backlight/brightness ];then 
    echo "password" | sudo -S chmod 777 /sys/class/backlight/intel_backlight/brightness 
fi 
:
read bright < '/sys/class/backlight/intel_backlight/brightness' 
 
v=0
v=$(($bright - 30 )) 
 
echo $v > /sys/class/backlight/intel_backlight/brightness 

后面的就比较简单了,直接在设置里面配置快捷键,然后把对应的命令写进去,比如ubuntu在设置-keyboard快捷键的command里面填

sh ..../brightness_up.sh

部分脚本引用自
http://jianshusoft.blog.51cto.com/2380869/810780

上一篇下一篇

猜你喜欢

热点阅读