小智 5
安装 xmacro (sudo apt-get install xmacro)
创建一个名为“myxmacro”的文件并为其提供以下内容:
代码:
MotionNotify 90 90
MotionNotify 120 120
Run Code Online (Sandbox Code Playgroud)
3. 创建一个文件“no.idle.sh”并使其可执行:
代码:
touch no.idle.sh
chmod +x no.idle.sh
Run Code Online (Sandbox Code Playgroud)
4.4. 创建一个文件“no.idle.sh”并使其可执行: 代码:
touch no.idle.sh
chmod +x no.idle.sh
Run Code Online (Sandbox Code Playgroud)
给它以下内容:
代码
#!/bin/bash
# No.idle.sh prevents GNOME to turn IDLE
# if there is any sound sent to speakers
# This script requires the package "xmacro"
# (apt-get install xmacro)
###########################################
# This script requires a textfile called "myxmacro"
# with the following (dummy) content:
# ------------ myxmacro ------------
# MotionNotify 90 90
# MotionNotify 120 120
# ----------------------------------
# You need to fix the path to "myxmacro" in line 31
#
#############################################
# set Log-File
LOG=/home/YOUR_USERNAME/noidle.log
sound=0
silence=0
while true; do
sleep 1
Datum=`date +%d.%m.%Y-%H:%M:%S`
# check if sound is sent to speaker
if pactl list | grep RUNNING > /dev/null; then
echo "[$Datum] Sound (Ping: $sound)" >> $LOG
sound=$((sound+1));
xmacroplay :0 </path/to/myxmacro
silence=0
else
echo "[$Datum] Silence (Ping: $silence)" >> $LOG
silence=$((silence+1));
sound=0
fi
#----------------------------------------------------
done
Run Code Online (Sandbox Code Playgroud)
您需要: - 修复第 18 行中日志文件的路径
修复第 31 行中“myxmacro”的路径
完毕。
脚本的作用: 脚本每秒检查一次是否有任何声音发送到扬声器(使用终端命令 pactl list | grep RUNNING)。
如果音乐正在运行,它会模拟鼠标移动(使用 xmacroplay)。这会导致您的 GNOME 会话不会运行 IDLE(因此您的 PC 不会挂起)。
如果没有播放音乐,它什么都不做(因此您的会话可以运行 IDLE,然后暂停)
您可以通过在终端中键入来观看检查音乐的脚本:
tail -f /path/to/noidle.log
Run Code Online (Sandbox Code Playgroud)