简体   繁体   English

如何从命令行确定我的 KDE 桌面是否处于锁定屏幕状态?

[英]How can I determine if my KDE Desktop is in lock screen state from command line?

I have a program run on the background that simply take a screenshot every N seconds.我有一个在后台运行的程序,它每 N 秒简单地截取一次屏幕截图。

eg:例如:

#!/bin/sh

while true; do
  take-screenshot
  sleep 10
done

What I want to achieve is only take screenshot if screen is not locking.我想要实现的只是在屏幕未锁定时截取屏幕截图。 eg:例如:

#!/bin/sh

while true; do
  if ! screen-is-locking; then
    take-screenshot
    sleep 10
  fi
done

How can I determine if my desktop is locking in command line?如何确定我的桌面是否在命令行中锁定?

According to this link provided by fellow comments under this question, I got a solution or workaround for my question, it works well under 5.4.58-1-MANJARO KDE Plasma (other DE might have different ways according to that answer's statement).根据此问题下的其他评论提供的链接,我为我的问题找到了解决方案或解决方法,它在 5.4.58-1-MANJARO KDE Plasma 下运行良好(根据该答案的声明,其他 DE 可能有不同的方法)。

There's a method in dbus service which well fit my need: dbus 服务中有一种方法非常适合我的需要:

#/bin/sh

is_screen_locking()
{
  if dbus-send --session --dest=org.freedesktop.ScreenSaver --type=method_call --print-reply /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.GetActive | grep 'boolean true' > /dev/null; then
    return 0
  else
    return 1
  fi
}



if is_screen_locking; then
   echo 'screen is locking'
else
   echo 'screen is not locking'
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM