解锁时运行脚本?

发布于 2024-07-23 05:45:33 字数 226 浏览 14 评论 0原文

嘿,我想在每次解锁计算机时运行一个 shell 脚本,在 KDE 4 上。我了解到我可以通过用 shell 脚本执行其操作来覆盖 /usr/lib/kde4/libexec/krunner_lock 来运行它,然后是原始的 krunner_lock 二进制文件,我基本上想做相反的事情:启动一个脚本来“撤消”锁定脚本的操作。 我使用的是 Kubuntu 9.04 64 位,但我很欣赏任何操作系统的答案,以防我想在该系统上做同样的事情。

Hey, I'd like to get a shell script to run everytime I unlock my computer, on KDE 4. I learned that I could run one by overwriting /usr/lib/kde4/libexec/krunner_lock with a shell script doing its thing, then the original krunner_lock binary, and I'd basically want to do the opposite: launch a script that "undoes" what the locking script does.
I'm on Kubuntu 9.04 64-bit but I appreciate answers for any operating system, in case I ever want to do the same on that system.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小猫一只 2024-07-30 05:45:33

这里的 KDE 论坛上找到了答案 。 波吉斯的解决方案非常接近答案,但还没有完全实现。 您必须将脚本接收到的参数传递给真正的 krunner_lock,如下所示:krunner_lock_bin $@

Figured it out on the KDE forums here. Porges's solution is pretty close to the answer but it's not quite there yet. You have to pass the arguments that the script receives to the real krunner_lock, like so: krunner_lock_bin $@

疯到世界奔溃 2024-07-30 05:45:33

此页面读取,似乎krunner_lock将保持运行状态只要屏幕锁定,因此您应该能够将命令放在运行它的行之后,并且一旦屏幕解锁,它们就会运行。

例如

#!/bin/bash
...
# do stuff
...
real_krunner_lock # exits once screen unlocks...
...
# undo stuff

Reading from this page, it seems like krunner_lock will stay running as long as the screen is locked, so you should be able to place the commands after the line that runs it and they will run once the screen unlocks.

e.g.

#!/bin/bash
...
# do stuff
...
real_krunner_lock # exits once screen unlocks...
...
# undo stuff
如此安好 2024-07-30 05:45:33

2015 年版本,在 Kubuntu 14.10 下使用桌面小部件储物柜运行:

#!/bin/bash

lockpidname="/usr/bin/plasma-overlay --nofork"

$lockpidname

check_slock () {
if [[ $(pgrep -fla $lockpidname) ]]; then 
SLOCKED=1
else
SLOCKED=0
fi
}

while true; do
  sleep 5
  check_slock
  case $SLOCKED  in 
  0) 
  echo "System unlocked run something here"
  break
  ;; 
  esac

done

适用于您想要在全局键盘快捷键的自定义部分下分配 CTRL+ATL+L 组合的情况。

Version for year 2015 that works under Kubuntu 14.10 using the Desktop Widgets locker:

#!/bin/bash

lockpidname="/usr/bin/plasma-overlay --nofork"

$lockpidname

check_slock () {
if [[ $(pgrep -fla $lockpidname) ]]; then 
SLOCKED=1
else
SLOCKED=0
fi
}

while true; do
  sleep 5
  check_slock
  case $SLOCKED  in 
  0) 
  echo "System unlocked run something here"
  break
  ;; 
  esac

done

This is for situation when you want to assign CTRL+ATL+L combination under the Custom section within the Global Keyboard Shortcuts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文