Stop/Start Music on Linux with a Keyboard Shortcut Using playerctl

If you use YouTube Music or similar music apps, you may have noticed there’s no built-in global media control, especially for play/pause shortcuts, and there’s nothing worse than having to find the app when somebody is calling you to pause it quickly.

Fortunately, there’s a clean and efficient way to solve this using the playerctl tool. In this guide, we’ll walk through setting up a global keyboard shortcut to control YouTube Music playback on Linux Mint, although the same steps will apply to all common music players and Linux distros.

Step 1 – Install playerctl

First, ensure playerctl is installed. This utility allows you to control media players that support MPRIS.

sudo apt install playerctl

Step 2 – Launch YouTube Music

Open YouTube Music or your music player of choice. Start playing a track to activate the media session and to give us something to hook into.

Step 3 – Verify It Works

Test playerctl in the terminal –

playerctl play-pause

If YouTube Music pauses or resumes playback, you’re good to go on the next step.

You can also optionally limit which app you’re targetting by running the playerctl -l command in the terminal to list all active apps that you can target, then appending the name to the end of the player ctl command like this –

playerctl -p edge.YoutubeMusic play-pause

Step 4 – Create a Custom Keyboard Shortcut

  1. Open System Settings > Keyboard > Shortcuts > Custom Shortcuts
  2. Click Add custom shortcut.
    • Name: Toggle YouTube Music
    • Command: playerctl play-pause
  3. Click the unassigned shortcut column and press your preferred key combo (e.g., Ctrl + Enter).

Further Steps

From here it’s really easy to also set up other commands, ones I’d suggest are shortcuts to skip and to go to the previous track. I personally have these linked to CTRL + Plus and CTRL + Minus –

playerctl previous
playerctl next
CommandDescription
playCommand the player to play.
pauseCommand the player to pause
play-pauseCommand the player to toggle between play/pause.
stopCommand the player to stop.
nextCommand the player to skip to the next track.
previousCommand the player to skip to the previous track.
position [OFFSET][+/-]Command the player to go to the position or seek forward or backward OFFSET in seconds.
volume [LEVEL][+/-]Print or set the volume to LEVEL from 0.0 to 1.0.
statusGet the play status of the player. Either “Playing”, “Paused”, or “Stopped”.
metadata [KEY...]Print the metadata for the current track. If KEY is passed, print only those values from the metadata.
open [URI]Command for the player to open a given URI. Can be either a file path or a remote URL.
loop [STATUS]Print or set the loop status. Either “None”, “Track”, or “Playlist”.
shuffle [STATUS]Print or set the shuffle status. Either “On”, “Off”.

Big thanks to the playerctl project found on GitHub and the many contributors who made this really simple to do – https://github.com/altdesktop/playerctl

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started