1

Is there a way of making Ubuntu (through the command line) to lock the screen after X minutes?

I need to do so for example:

  • I'm watching a two-hours movie, so I need to make Ubuntu lock the screen that after 123 minutes.

2 Answers 2

3

Use:

gnome-screensaver-command --lock

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


But there is a more convenient way:

  1. Set Ubuntu to lock the 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.)
1
  • How do you set Ubuntu to lock the screen after 5 minutes of inactivity? Commented Jan 30, 2018 at 18:15
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .