1

I want to map my mouse button 5 such that option + button 5 skips to the next track if pressed once, and if held down it continuously skips forward by 10 seconds.

I've added the following rule to Karabiner:

{
  "title": "Mouse Button Remapping",
  "rules": [
    {
      "description": "Maps option + button 5 to next track",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "pointing_button": "button5",
            "modifiers": {
              "mandatory": [
                "option"
              ]
            }
          },
          "to_if_alone": [
            {
              "key_code": "rewind"
            }
          ],
          "to_if_held_down": [
            {
              "shell_command": "osascript -e 'tell application \"Spotify\" to player position' | awk '{ print $1 - 10 }' | xargs -I {} osascript -e 'tell application \"Spotify\" to set player position to {}'",
              "repeat": true
            }
          ]
        }
      ]
    }
  ]
}

For some reason though, when I hold down option + button 5, the track will skip forward 10 seconds just once.

The weird thing is, if I replace the shell_command in the to_if_held_down block to just be "key_code" : "rewind", then a ton of rewind events are sent to Spotify.

Is there a configuration option I'm missing?

FWIW I'm also running bearded spice such that all media key events are sent solely to Spotify.

1 Answer 1

1

The Karabiner-Elements documentaion for "to.repeat" explains:

The default value is true.
The key repeating will be suppressed if to.repeat is false. 

Obviously a "repeat: true" line is pointless – you cannot "enforce" a repetition; it's default anyway.

But more important for your script:
"shell_command" unfortunately is NOT a "key" – "rewind" IS a key.
Therefore, "shell_command" can not be repeated by holding the original "from-key".
And: in any sequence of "key_code"s only the last one would be repeated (see link above).

I was pointed to the reason for this behaviour by little-big-h (github.com):

I found the code that makes karabiner send a key-up event before sending 
the next key-down event in a sequence. It can be disabled using this patch. 

His patch requires you to compile Karabiner-Elements from source code; that's too much for me … sorry.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .