Is there any way of making ubuntu (through CLI) to lock screen after X minutes?

I need to do so for example:

  • I'm watching a 2Hours movie, so I need to make ubuntu that after 123 minutes to lock screen.
link|improve this question

55% accept rate
feedback

2 Answers

up vote 3 down vote accepted

GNOME Screensaver can be activated using a DBus call:

gdbus call -e -d org.gnome.ScreenSaver -o / -m org.gnome.ScreenSaver.Lock

Edit: I completely forgot about this:

gnome-screensaver-command --lock

So you could run, for example, ((sleep $[123*60]; gnome-screensaver-command -l)&) to run it after 123 minutes (123*60 seconds).


But there is a more convenient way:

  1. Set Ubuntu to lock screen after 5 minutes of inactivity.
  2. Configure the movie player to keep the session "active" while the movie is playing. Totem does it automatically; other players usually have some way or other. (The option might be called "inhibit screensaver" or similar.)
link|improve this answer
+1, will try it out asap... – w0rldart Feb 10 at 19:43
feedback

Remember that you can simplify that command. gnome-screensaver-command --lock is quite a long command to write, so you can make it easier by creating an alias for it.

Simply run

gedit ~/.bashrc

Now scroll down to the end of the file and add the following line

alias lock='gnome-screensaver-command --lock'

After having saved the file, whenever you run the command lock it actually executes gnome-screensaver-command --lock. Remember that .bashrc isn't a file you would normally see in your home folder because it is hidden by default. If you want it to pop into view just browse to your home folder in nautilus and press Ctrl + H.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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