抓住盖子关闭和打开事件

rub*_*o77 9 acpi lid events touchscreen 14.04

我试着写一个这样的建议的脚本:

当我合上盖子时,如何将屏幕设置为锁定?

我创建了一个目录和一个新的脚本文件:

mkdir /etc/acpi/local
gksudo gedit /etc/acpi/local/lid.sh.post
Run Code Online (Sandbox Code Playgroud)

/etc/acpi/local/lid.sh.post包含以下代码的文件:

#!/bin/sh

#########################################################################
## Script written by Ruben Barkow                                      ##
## https://gist.githubusercontent.com/rubo77/1a3320fda5a47fdebde7/raw/87cde3f0554467a132aba3cda7ad3c5e7187571f/lid.sh.post
## Description: This script reacts if laptop lid is opened or          ##
## closed in Ubuntu 11.10 (Oneiric Ocelot).                            ##
##                                                                     ##
## This script can be freely redistributed, modified and used.         ##
## Any redistribution must include the information of authors.         ##
##                                                                     ##
## THIS SCRIPT HAS NO WARRANTY!                                        ##
#########################################################################

grep -q close /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo close>>/tmp/screen.lid
fi
grep -q open /proc/acpi/button/lid/*/state
if [ $? = 0 ]; then
    echo open>>/tmp/screen.lid
fi
Run Code Online (Sandbox Code Playgroud)

我试图让它在 Ubuntu 14.04 中运行,但为什么这没有效果。

Ubuntu 14.04 中是否有一种新方法来捕捉盖子关闭和打开事件?

rub*_*o77 13

我在这里得到一个提示:https : //askubuntu.com/a/518825/34298

  • 您要在盖子打开或关闭时调用的脚本必须存储
    /etc/acpi/lid.sh.

  • 然后必须创建正确的文件/etc/acpi/events/lm_lid,其内容如下:

    event=button/lid.*
    action=/etc/acpi/lid.sh
    
    Run Code Online (Sandbox Code Playgroud)
  • 重新启动系统以使其生效。或者使用以下命令重新启动 ACPI 就足够了

    sudo /etc/init.d/acpid restart
    
    Run Code Online (Sandbox Code Playgroud)

  • 无需重新启动即可重新启动 ACPI 对我来说很有效! (2认同)