由于Ubuntu系统的驱动问题,我在笔记本上的亮度调节快捷键基本上用不了,所以写了下面这个脚本来调节笔记本亮度,然后把脚本映射到自定义快捷键上。下面分享具体方法。
原理 控制亮度文件的文件在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 说明: 1.brightness里面保存的是当前亮度。 2.max_brightness里面保存的是亮度最大值。 3.所以直接修改brightness的值就可以调节亮度了。
具体操作 1.首先修改brightness的权限: sudo chmod 777 /sys/class/backlight/intel_backlight/brightness 2.然后可以执行命令测试是否能调节亮度 1].调节亮度为100: echo 100 > /sys/class/backlight/intel_backlight/brightnes 2].调节亮度为0: echo 0 > /sys/class/backlight/intel_backlight/brightnes 如果上面的操作成功了就可以开始写脚本了。 3.亮度增加: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 4.亮度降低: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 5.后面的就比较简单了,直接在设置里面配置快捷键,然后把对应的命令写进去,比如Ubuntu系统在设置-keyboard快捷键的command里面填写: sh ..../brightness_up.sh 至此,在Ubuntu系统调节亮度快捷键修复目的达到。
相关主题 |