Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.
share|improve this question
add comment

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.)
share|improve this answer
    
+1, will try it out asap... –  w0rldart Feb 10 '12 at 19:43
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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