Categories: Linux & UnixUbuntu

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

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
Sponsored
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:

./pause-on-lock.sh

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.

Sponsored

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:

Clementine
Spotify
Rhythmbox
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.

The post How to automatically pause/play songs upon screen lock/unlock in Ubuntu appeared first on FAQforge.

Ubuntu Server Admin

Recent Posts

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

14 hours ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

14 hours ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

14 hours ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

2 days ago

Revolutionizing Web Page Creation: How Structured Content is Slashing Design and Development Time

Co-authored with Julie Muzina A year ago, during our Madrid Engineering Sprint, we challenged ourselves…

3 days ago

Ubuntu Weekly Newsletter Issue 897

Welcome to the Ubuntu Weekly Newsletter, Issue 897 for the week of June 15 –…

3 days ago