I have a program run on the background that simply take a screenshot every N seconds.
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).
There's a method in dbus service which well fit my need:
#/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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.