dbus-monitoring loop exits automatically
我正在尝试在屏幕锁定/解锁时执行bash命令。
以下教程
1 2 3 4 5 6 7 8 9 10 | #!/bin/bash while true; do dbus-monitor --session"type='signal',interface='org.gnome.ScreenSaver'" | while read -r sign; do case"$sign" in *"boolean false"*) echo"Screen unlocked";; *"boolean true"*) echo"Screen locked";; esac done done |
我将
以下脚本在Linux Mint Cinnamon上对我有用。注意"肉桂"而不是"侏儒";如果不确定使用什么,请运行
1 2 | me@localhost ~] echo $DESKTOP_SESSION cinnamon |
这是脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/bin/bash while true; do #added to try to solve the issue, but alas it did not dbus-monitor --session"type='signal',interface='org.cinnamon.ScreenSaver'" | while read sign; do case"$sign" in *[Ff]alse*) echo"Screen unlocked";; *[Tt]rue*) echo"Screen locked";; *) echo"`date` Unknown";; esac sleep 0.250 done done |
像这样运行:
1 | nohup ./myprogram </dev/null >| $HOME/myprogram.out 2>&1 & |