如何在 Ubuntu 15.10 中拔掉交流电时自动降低亮度?
我尝试按照这里的建议修改 dconf-editor 设置,https://askubuntu.com/a/312619/511925,但在Ubuntu 15.10中不再有这样的设置。
我尝试安装 Cuttlefish,但它不适用于 Ubuntu 15.10。
有任何想法吗?
答案1
介绍
下面的脚本使用dbus
shellon_ac_power
脚本(Ubuntu 默认自带)来轮询交流适配器是否存在,并根据$HOME/.auto-backlightrc
文件中设置的值设置亮度。
安装
git
通过终端安装:
- 运行
sudo apt-get install git
安装git
- 运行。如果已存在,
mkdir $HOME/bin
则跳过此步骤$HOME/bin
cd $HOME/bin
- 跑步
git clone https://github.com/SergKolo/sergrep.git
- 该脚本将位于
$HOME/bin/sergrep/auto-backlight.sh
。确保脚本可以使用chmod +x $HOME/bin/sergrep/auto-backlight.sh
- 将脚本添加为启动应用程序。在 Unity Dash 或 Gnome 搜索中查找启动应用程序菜单。或者,
gnome-session-properties
在终端中运行命令以启动菜单。将脚本的完整路径添加为启动应用程序,以便每次登录 GUI 时都会启动它。
或者,您可以自行复制并保存脚本源,chmod +x file
并执行上面描述的步骤#6。
要使脚本在每次登录 Gnome 或 Unity 时自动启动,请使用启动应用程序公用事业。
笔记:如果您希望脚本始终设置 AC 亮度,请取消注释第 60 行和第 61 行的 else 语句,特别是这一部分
# The two lines bellow are optional for
# setting brightness if on AC. remove #
# if you want to use these two
# else
# change_brightness $INCREASE
脚本源
#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: [email protected]
# Date: February 26 2016
# Purpose: Brightness control that polls for
# ac adapter presence. Uses
# Dependencies: on_ac_power script, dbus, Unity/Gnome
# Written for: https://askubuntu.com/q/739617/295286
# Tested on: Ubuntu 14.04 LTS
###########################################################
# Copyright: Serg Kolo , 2016
#
# Permission to use, copy, modify, and distribute this software is hereby granted
# without fee, provided that the copyright notice above and this permission statement
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
# uncomment the line bellow for debugging
#set -x
ARGV0="$0"
ARGC=$#
main()
{
# defaults
local DISPLAY=:0
local DECREASE=30
local INCREASE=75
local RCFILE="$HOME/.auto-backlightrc"
#---
# Check the settings
if [ -f $RCFILE ]
then
source $RCFILE
else
create_rcfile $DECREASE $INCREASE
fi
#---
# now actually test if we're using ac adapter
if ! on_ac_power
then
change_brightness $DECREASE
# The two lines bellow are optional for
# setting brightness if on AC. remove #
# if you want to use these two
# else
# change_brightness $INCREASE
fi
}
change_brightness()
{
dbus-send --session --print-reply\
--dest=org.gnome.SettingsDaemon.Power\
/org/gnome/SettingsDaemon/Power \
org.gnome.SettingsDaemon.Power.Screen.SetPercentage uint32:"$1"
}
create_rcfile()
{
echo "DECREASE="$1 > "$RCFILE"
echo "INCREASE="$2 >> "$RCFILE"
}
while true
do
main
sleep 0.25
done