Detecting screen lock

Greetings! I just moved from cinnamon and am having some difficulties adapting a script, I was hoping this community could give me a hand.

I am trying to detect whether or not the screen is locked from the root crontab.

Before it was enough with $(su $user -c "cinnamon-screensaver-command -q"), but it seems to be a bit more complicated here. After searching I found these two:

qdbus org.freedesktop.ScreenSaver /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.GetActive

dbus-send --session --dest=org.freedesktop.ScreenSaver --type=method_call --print-reply /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.GetActive

However I can’t get them to work in that environment, and the more I search the more complicated it seems to get it; I can’t even get it to work with sudo. I was wondering, is there a simpler alternative, or is it even possible? Thanks!

Sounds a bit like an XY question. Maybe it’s time to step back and ask about what you’re trying to do here. We might be able to find a better way for you to accomplish the goal.

It’s just a script to shut down or hibernate the computer depending on the time that has passed with no users logged on, or with all users locked, or the idle time of the unlocked user.

It would be desirable not to have to make it much more complicated than with cinnamon.

Ok.

The process name is kscreenlocker_greet.

This will do the trick, thanks.