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.

3 Responses to Quick Hack: Global Hotkeys for SMPlayer

  1. anis abdo says:

    Please explain the detailed on YouTube
    I need this road very much but I do not understand the steps
    I ask you to make an explanation I need you badly 🙁

    • Sorry, but I don’t do video tutorials and, even if I did, I haven’t logged into YouTube since Google started requiring that I create a Google Profile (ie. tell them more about me) to post comments.

      However, if you can explain where you’re having trouble, I’d be happy to improve the instructions.

  2. MarcelV says:

    Thanks! Just what I needed. I used VLC before because there global hotkkeys work but now I’m using SMPlayer.
    Thanks, bye!

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.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.