pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.53k stars 834 forks source link

Controlling Caps Lock LED during Complex Modifications #3493

Open revolter opened 1 year ago

revolter commented 1 year ago

Revival of #1257.

Having this complex modification:

{
    "title": "Caps Lock useful",
    "rules": [
        {
            "description": "Caps Lock to mute/unmute",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "caps_lock"
                    },
                    "to": [
                        {
                            "set_variable": {
                                "name": "is_caps_lock_active",
                                "value": 1
                            }
                        },
                        {
                            "shell_command": "osascript -e 'tell application \"System Events\" to set volume input volume 100'"
                        }
                    ],
                    "conditions": [
                        {
                            "type": "variable_if",
                            "name": "is_caps_lock_active",
                            "value": 0
                        }
                    ]
                },
                {
                    "type": "basic",
                    "from": {
                        "key_code": "caps_lock"
                    },
                    "to": [
                        {
                            "set_variable": {
                                "name": "is_caps_lock_active",
                                "value": 0
                            }
                        },
                        {
                            "shell_command": "osascript -e 'tell application \"System Events\" to set volume input volume 0'"
                        }
                    ],
                    "conditions": [
                        {
                            "type": "variable_if",
                            "name": "is_caps_lock_active",
                            "value": 1
                        }
                    ]
                }
            ]
        }
    ]
}

causes the Caps Lock key's LED to stop working.


I also tried adding

{
    "key_code": "caps_lock"
}

under the to key, with the idea that the complex modification would then act as a proxy. But instead, you now have to press caps lock twice to toggle the LED once.

revolter commented 1 year ago

A temporary workaround would be to use notifications:

{
    "title": "Caps Lock useful",
    "rules": [
        {
            "description": "Caps Lock to mute/unmute",
            "manipulators": [
                {
                    "type": "basic",
                    "from": {
                        "key_code": "caps_lock"
                    },
                    "to": [
                        {
                            "set_variable": {
                                "name": "is_caps_lock_active",
                                "value": 1
                            }
                        },
                        {
                            "shell_command": "osascript -e 'tell application \"System Events\" to set volume input volume 100'; osascript -e 'display notification \"🔈 Unmuted\" with title \"Microphone state changed\"'"
                        }
                    ],
                    "conditions": [
                        {
                            "type": "variable_if",
                            "name": "is_caps_lock_active",
                            "value": 0
                        }
                    ]
                },
                {
                    "type": "basic",
                    "from": {
                        "key_code": "caps_lock"
                    },
                    "to": [
                        {
                            "set_variable": {
                                "name": "is_caps_lock_active",
                                "value": 0
                            }
                        },
                        {
                            "shell_command": "osascript -e 'tell application \"System Events\" to set volume input volume 0'; osascript -e 'display notification \"🔇 Muted\" with title \"Microphone state changed\"'"
                        }
                    ],
                    "conditions": [
                        {
                            "type": "variable_if",
                            "name": "is_caps_lock_active",
                            "value": 1
                        }
                    ]
                }
            ]
        }
    ]
}