How to create shortcut to stop and minimize media player

Step 1: Go to your terminal.

Step 2: Inside the terminal, type cd and press enter. This will change to your home directory.

Step 3: In the same terminal, run this command touch pause-and-minimize-vlc.sh. This will create an empty text file in your home directory.

Step 4: Open pause-and-minimize-vlc.sh with a text editor (kate, mousepad, or whichever text editor you prefer).

Step 5: Paste the following into pause-and-minimize-vlc.sh

#!/bin/sh
winclass=$(xdotool getactivewindow getwindowclassname)
if [ "$winclass" = "Vlc" ]
then
     # only takes effect if the current active window is vlc
     xdotool minimize $(xdotool getactivewindow)
     playerctl --player=vlc pause
fi

Step 6: Save the file.
Step 7: Go back to your terminal and type

chmod +x ~/pause-and-minimize-vlc.sh

This will make the shell script executable.

Step 8: Add a keyboard shortcut to run this shell script every time the shortcut is pressed. How you do this depends on the desktop environment you’re using. If you are using XFCE or KDE, there are probably graphical tools to do this. I don’t recommend binding the ESC key for this function, since the ESC key has its own uses. Choose something like Win + M or something.

3 Likes