One thing that bugged me about KDE was the lack of Global Media Shortcuts with music/video players. If you want a key for the Play/Pause, Next, Previous, or Stop functions you might have noticed they are assigned to Amarok by default. Well I wanted to be able to pause my music no matter if it was playing through Amarok, Banshee, Pithos, or any other player.
One caveat at the moment, this only works with applications that support MPRIS or "Media Player Remote Interfacing Specification". A large amount of media applications already support this but if you aren't sure open your application and type this code in a terminal.
If you see your apps name after typing this command into the terminal then it will work. Make sure your application is open before you run this command.
[Overview]
The overview of my fix:
Say I want to be able to set the Play/Pause button to work on any media player allowing me to play or pause the music. First create a script to send the the Play/Pause command to your applications.
Here's my script for Play/Pause:
If you notice the actual command is specified at the end of the 2nd to last line. This "PlayPause" instructs the application to do what we want. But what if we want to add a Next Song key? Just copy this script and change the "PlayPause" to "Next". Pretty simple.
Now all we have to do is assign this script to a global shortcut. In KDE go to System Settings > Shortcuts and Gestures > Custom Shortcuts. Right click in the white space and select New > Global Shortcut > Command URL. Name your Action whatever you like and now click the Trigger tab and assign your appropiate shorcut. Now click the Action tab and browse to your previously made script. Make sure your script is executable by quickly typing "chmod +x /home/USER/script". After you click Apply you should be able to control all supported media applications with your shortcut!
One caveat at the moment, this only works with applications that support MPRIS or "Media Player Remote Interfacing Specification". A large amount of media applications already support this but if you aren't sure open your application and type this code in a terminal.
Code:
qdbus | grep org.mpris.MediaPlayer2 | sed 's/.*\.//'
[Overview]
The overview of my fix:
Say I want to be able to set the Play/Pause button to work on any media player allowing me to play or pause the music. First create a script to send the the Play/Pause command to your applications.
Here's my script for Play/Pause:
Code:
#!/bin/bash ## -- This script will imitate Gnome's Media Controls (Play/Pause, Next, Previous, Stop) -- ## ## -- It will assume you are using a media application that is compatible with MPRIS or -- ## ## -- "Media Player Remote Interfacing Specification" -- ## # Search for running media applications # and store into apps array apps=(`qdbus | grep org.mpris.MediaPlayer2 | sed 's/.*\.//'`) # For each application send the "PlayPause" command for app in "${apps[@]}" do qdbus org.mpris.MediaPlayer2.$app /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause done
Now all we have to do is assign this script to a global shortcut. In KDE go to System Settings > Shortcuts and Gestures > Custom Shortcuts. Right click in the white space and select New > Global Shortcut > Command URL. Name your Action whatever you like and now click the Trigger tab and assign your appropiate shorcut. Now click the Action tab and browse to your previously made script. Make sure your script is executable by quickly typing "chmod +x /home/USER/script". After you click Apply you should be able to control all supported media applications with your shortcut!
Comment