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 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.

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

How to Harden Security of VPS Server

This article demonstrates how to harden security of VPS server and is intended for server…

15 hours ago

How to install Wget on Ubuntu 24.04

In this blog post, we will guide you on how to install wget on Ubuntu…

1 day ago

Xfwl4 – The roadmap for a Xfce Wayland Compositor

Jan 27,2026 Xfwl4 - The roadmap for a Xfce Wayland Compositor We, the Xfce team…

4 days ago

🚀 Deploy n8n on Ubuntu VPS (Quick-Start Guide)

This article provides a step-by-step how-to guide to deploy n8n on Ubuntu VPS. What is…

5 days ago

How to avoid package End of Life through backporting

In July 2025, git received CVE-2025-48384, a high vulnerability allowing arbitrary code execution when cloning…

1 week ago

Showcasing open design in action: Loughborough University design students explore open source projects

Last year, we collaborated with two design student teams from Loughborough University in the UK.…

2 weeks ago