Quick Hack: Global Hotkeys for SMPlayer

I have a family member who has grown used to pausing Audacious Media Player with a quick press on their XF86AudioPlay key, but half of what they listen to is video files, so I wrote a quick shell script to work around SMPlayer‘s lack of global hotkey support.

Instructions:

  1. Install xdotool (on Debian/Ubuntu/Mint)
  2. Put the script somewhere and set it executable
  3. Use your desktop’s global hotkey support or a utility like xbindkeys to run the script whenever something like Ctrl+XF86AudioPlay is pressed.

If you want it to do something other than play/pause, the simplest solution is probably to replace space with "$@"  (including quotes) inside the script, save it under a name like smplayer_remote.sh, and then set up associations like these:

  • XF86AudioPlaysmplayer_remote.sh space
  • XF86AudioRewindsmplayer_remote.sh Left
  • XF86AudioForwardsmplayer_remote.sh Right

(You can find the keysym names using the xev tool (on Debian/Ubuntu/Mint) and man xdotool will tell you how to specify modifier keys like Ctrl and Alt)

I initially tried to make it behave exactly like a real global hotkey would, but xdotool seems to have an unavoidable race condition and no way to force a 100ms delay after using the windowfocus command… so, instead, this will momentarily switch window focus, then restore whatever you were working on before.

It should be possible to do it properly if I were willing to either patch xdotool or drop down and write against the bare X11 APIs, but I just don’t have the time for either and this is Good Enough™ for the intended use case.

CC BY-SA 4.0 Quick Hack: Global Hotkeys for SMPlayer by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.