Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Prototype/principle for a wrapper script for multiple media players to use the same Openbox keybindings, depending on which one is running
Posted 03-25-2021 at 10:50 AM by the dsc
Most likely not the most elegant way of doing it, and not fully functional (for mpv) regarding the display of media info:
I just gave up trying to "grep" the title from mpv after a few tries. But otherwise it works. The rationale couldn't be simpler, if mpv is running, the script will handle it, otherwise it defaults to mpc (through another script, in this case, which handles the notify-send OSD correctly for mpv, besides other things, like a pipe menu for openbox and this kind of stuff).
Theoretically all wanted commands can be handled by a single script, with the openbox keybinding specifying the command with a parameter, like "mediaplayerwrapper.sh nexttrack," rather than a script for each command, which is how I first "implemented" it in order to give it a try.
The media player hierarchy or selection can possibly be made more sophisticated, with something like using /dev/shm/ files to communicate with itself regarding what was the most recently used media player and whatnot. Maybe one can even detect if a browser is playing something and do some xdotool+wmctrl vodoo with it and unify everyhing. If I ever do that, it would be hard not to celebrate by yelling, "it's ALIVE! It's ALIVE!!"
Code:
#!/bin/bash if pgrep -x mpv ; then echo '{"command": ["playlist-next"]}' > /tmp/mpvsocket #title=$(echo '{ "command": ["get_property", "media-title"] }' > /tmp/mpvsocket) #title=( $(wmctrl -l | grep mpv$ ) ) #title=$(echo ${title[@]:3} | sed 's| - mpv||' ) DISPLAY=:0 notify-send "> > > >" --icon=mpv else obmpc.sh next fi
Theoretically all wanted commands can be handled by a single script, with the openbox keybinding specifying the command with a parameter, like "mediaplayerwrapper.sh nexttrack," rather than a script for each command, which is how I first "implemented" it in order to give it a try.
The media player hierarchy or selection can possibly be made more sophisticated, with something like using /dev/shm/ files to communicate with itself regarding what was the most recently used media player and whatnot. Maybe one can even detect if a browser is playing something and do some xdotool+wmctrl vodoo with it and unify everyhing. If I ever do that, it would be hard not to celebrate by yelling, "it's ALIVE! It's ALIVE!!"
Total Comments 0