3

I am trying to create a little script to set random message when i lock the screen of my computer.

So i need to be able to define a message from command line and call it when i will execute the lock screen function.

I find the command to lock the screen : cinnamon-screensaver-command -l but in the man there is no details about how to define the lock screen message.

If you have some ideas...

1
  • There is a dbus method org.cinnamon.ScreenSaver / ShowMessage. It doesn't seem to work for me, though.
    – s3lph
    Dec 7 '15 at 13:10
3

cinnamon-screensaver-command now has a "-m" or "--away-message" option for this, so you can just use that. I've got a little shell script that reads something like:

#!/bin/sh

cinnamon-screensaver-command -l -m $(fortune -s)

2

The Cinnamon screensaver offers the DBus service org.cinnamon.ScreenSaver, which, among others, has the following method:

method void org.cinnamon.ScreenSaver.Lock(QString body)

This method is exactly the one being called when locking the screen with a custom message. If you want to call this from a bash script, you need a DBus frontend, such as gdbus or qdbus.

I personally prefer qdbus, as I haven't understood gdbus' syntax yet. You may, however, have to install qdbus first with

sudo apt-get install qdbus

This may install some other Qt libraries, as well. When installed, you can call the method using

qdbus org.cinnamon.ScreenSaver / Lock "$message"

with $message containing your custom message. This method call, however, will not work if the screen is already locked. If this is the case, the method will block until the screen is unlocked and then returns without re-locking the screen.

3
  • Thank you very much ! Do you have any idea on how to link the lock action to my script ? Or to add keyboard shortcut ? Dec 7 '15 at 14:06
  • You can define custom keyboard shortcuts in Cinnamon's keyboard settings. Locking the screen is built into Cinnamon, so have fun patching and recompiling it yourself ;)
    – s3lph
    Dec 7 '15 at 15:17
  • Didn't work for me on 19.3 $ qdbus org.cinnamon.ScreenSaver / Lock "hrm" - Cannot find '.Lock' in object / at org.cinnamon.ScreenSaver
    – Tim Abell
    Jun 11 '20 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.