I use Karabiner-Elements to re-bind the F1 and F2 keys to run my own Application which increases and decreases the brightness.
This prevents the overlay from being shown.
I edited the ~/.config/karabiner/karabiner.json
file to add a rule to Karabiner-Elements:
"rules": [
{
"description": "Assign brightness conrol to brightness keys, but hides the overlay",
"manipulators": [
{
"from": {
"key_code": "f1",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "open -a DecreaseRetinaDisplayBrightness.app"
}
],
"type": "basic"
},
{
"from": {
"key_code": "f2",
"modifiers": {
"mandatory": [
"fn"
]
}
},
"to": [
{
"shell_command": "open -a IncreaseRetinaDisplayBrightness.app"
}
],
"type": "basic"
}
]
}
]
I am going to make my own apps DecreaseRetinaDisplayBrightness.app
et al. because I need to be able to grant my AppleScripts assistive access, and I don't know how to grant osascript
itself assistive access.
To make the Apps create a new Application in Automator:
The code to increase brightness by 1/16 at a time is this:
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
set value of value indicator 1 of slider 1 of group 2 of tab group 1 to (get (value of value indicator 1 of slider 1 of group 2 of tab group 1) + 0.0625)
end tell
quit application "System Preferences"
Obviously to decrease it's the same thing but subtracting 0.625
instead of adding it.
I saved the Application in my Applications folder, then granted it assistive access from System Preferences > Security & Privacy > Privacy > Accessibility:
Now hitting fnF2 increases the brightness without showing any pop-up. Obviously some of the above steps have to be repeated to create the DecreaseBrightness App.
Of course an almost identical method can be employed for volume and keyboard lights. Just write an AppleScript that controls each.
E.g. my "shell_command"
for volume decrease looks like
osascript -e 'set volume alert volume ((alert volume of (get volume settings)) - 100/16)' && osascript -e 'set volume (alert volume of (get volume settings))*7/100'
While it works it's not a perfect solution, it can sometimes momentarily steal focus, and is much laggier than Apple's default.
I wonder if the lagginess can be improved by adjusting some of Karabiner's settings,
"parameters": {
"basic.simultaneous_threshold_milliseconds": 50,
"basic.to_delayed_action_delay_milliseconds": 500,
"basic.to_if_alone_timeout_milliseconds": 1000,
"basic.to_if_held_down_threshold_milliseconds": 500
}
The lag can be made less annoying by increasing the 0.0625 to larger values, so that you can faster get to the brightness you want (although with less precision). The 0.0625 was chosen to simulate the steps taken by Apple by default (1/16).
An ideal solution would be the updated version of the
sudo defaults write /System/Library/LaunchAgents/com.apple.OSDUIHelper Disabled --bool YES
command that works for High Sierra 10.13.3.
I also don't know how to fix this error that occurs if System Preferences is already open and doesn't have focus: