在 KDE 中在屏幕锁定时运行脚本

dud*_*das 6 kde shell-script screen-lock

有没有办法在锁定当前 KDE 会话时运行 bash 脚本?

小智 7

这可能取决于您运行的 KDE 版本,但如果您在系统设置中有通知条目,那么您可以使用屏幕保护程序控件在屏幕锁定和解锁时运行脚本。

KDE 通知系统设置模块


Bob*_*Bob 5

在 KDE 和其他一些桌面环境中,您可以在 dbus 上监听接口org.freedesktop.ScreenSaver

执行此操作的脚本如下所示:

dbus-monitor --session "type='signal',interface='org.freedesktop.ScreenSaver'" |
  while read x; do
    case "$x" in 
      # You can call your desired script in the following line instead of the echo:
      *"boolean true"*) echo SCREEN_LOCKED;;
      *"boolean false"*) echo SCREEN_UNLOCKED;;  
    esac
  done
Run Code Online (Sandbox Code Playgroud)

另请参阅此问题以获取更多信息。