How to automatically pause/play songs upon screen lock/unlock in Ubuntu

Last Updated on April 18, 2021 by admin

There are times when while listening a song on computer and doing work in parallel, we need to take a short break (to talk to someone or for some other purpose). What do most of us do in this case: simple, pause the song and lock the screen. Then after the break is over, we unlock the system, and click the play button to resume playback.

While there isn't a lot of work required in this process already, if you want, you can automate a couple of steps - that of pausing and resuming the playback. In this tutorial, we will learn how you can do this. Please note that all commands and instructions mentioned here have been tested on Ubuntu 16.04LTS.

Pause on Lock

Yeah, that's the name of the tool that'll do the trick for you. Pause on Lock is basically a shell script that you need to run. Once that is done, the pause on lock and resume on unlock work gets automated.

Interested? You can download and install the tool from it's official GitHub page. Then all you have to do execute the shell script. For example, I executed the following command after entering the downloaded directory:



Note that you may need to provide executable privileges to this shell script before you execute it, something which you can do using the following command:

chmod +x pause-on-lock

To learn more about the chmod command, head here.

Now, whenever I locked the screen while listening to music, the audio automatically paused. Also, playback resumed automatically on screen unlock.

So that's pretty much about it. Please note that the tool doesn't work during logout and login. Also, out of the box, it's only compatible with the following music players:

Quod Libet
Google Play Music Desktop Player

You can have more names added to that list if you have playerctl installed. More information related to this can be found on Pause on Lock's GitHub page.

Leave a Comment