从睡眠中恢复后如何运行脚本?

Nax*_*mus 2 startup-applications

我有一个自定义脚本(使用 $DISPLAY)来设置鼠标上的额外按钮。我想每次登录系统时都运行这个脚本。我已通过 Ubuntu (18.10) GUI (Gnome 3.30.1) 将脚本添加为启动应用程序。它在我打开电脑或重新启动电脑后运行,但在电脑从睡眠状态恢复后无法运行。

如何在 PC 从睡眠状态恢复后运行脚本?(最好无需维护单独的脚本)。

Win*_*nix 5

从挂起恢复时运行脚本

创建一个新文件/lib/systemd/system-sleep/resume并复制到:

#!/bin/sh

case $1/$2 in
  pre/*)
    echo "Going to $2..."
    # Place your pre suspend commands here, or `exit 0`
    # if no pre suspend action required
    exit 0
    ;;
  post/*)
    echo "Waking up from $2..."
    # Place your post suspend (resume) commands here, or `exit 0` 
    # if no post suspend action required
    mouse_script.sh
    ;;
esac
Run Code Online (Sandbox Code Playgroud)

注意:mouse_script.sh用您的脚本名称替换用户(从底部算起第三行)。如果脚本不在您的路径中,请提供完整路径名 ( echo $PATH)。

然后使用以下命令将其标记为可执行:

sudo chmod +x /lib/systemd/system-sleep/resume
Run Code Online (Sandbox Code Playgroud)