Simple program that keeps track of the last used MPRIS2 players.
It prints the order of the players, from most recent to last recent, on a single
line on stdout
any time a player appears or disappears. The most recent list
of players is also written at /tmp/lastplayer
.
You can use this program to control from keybinds the most recently opened multimedia player, using for example a program like playerctl.
Using the same technique, you may control another player based on the order of when it was started.
Start lastplayer
beforehand:
lastplayer &
Toggle the playing state of the most recent player:
#!/bin/sh
player="$(cat /tmp/lastplayer | head -n 1)"
playerctl -p $player play-pause