我嘗試編寫一個像這樣的建議的腳本:
我建立了一個目錄和一個新的腳本檔案:
mkdir /etc/acpi/local
gksudo gedit /etc/acpi/local/lid.sh.post
該文件/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
我嘗試在 Ubuntu 14.04 中運行它,但為什麼沒有效果。
Ubuntu 14.04 中是否有一種新方法來捕捉蓋子關閉和打開事件?
答案1
我在這裡得到一個提示:https://askubuntu.com/a/518825/34298
當蓋子打開或關閉時要呼叫的腳本必須儲存
在/etc/acpi/lid.sh
.然後必須創建正確的文件
/etc/acpi/events/lm_lid
,其內容如下:event=button/lid.* action=/etc/acpi/lid.sh
重新啟動系統以使此生效。或者也許使用以下命令重新啟動 ACPI 就足夠了
sudo systemctl restart acpid.service