I'm looking for a solution to use just a simple keyboard shortcut to quickly toggle the brightness level from any percentage to 0% or any percentage to 50% or any percentage to 100%.
1 Answer
Ok so I've tried to find any shell command or any simple solution but I couldn't find any simple shell command that I can put on my karabiner.json file. Although I found this osascript -e 'tell application "System Events"' -e 'key code 144/145' -e ' end tell'
and I can use it like this way echo; for i in $(seq 4); do osascript -e 'tell application "System Events"' -e 'key code 144/145' -e ' end tell'; done
. But obviously it won't know the exact level and won't go to the exact level. Maybe I can just only use it to move quickly though the brightness level, like 4 dots.
However as everyone here commenting about a terminal based package called Brightness. So I just tried it myself, altho I was cautious as there was bit warning bout this app on their GitHub and after installing it I also saw it's limitation as well. But nonetheless it is working for my machine.
As I hardly ever uses this function key for play pause rewind (use spacebar left right key for that) so I did put this way on my karabiner.json...
{
"description": "f7 to 0% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f7"
},
"to": [
{
"shell_command": "osascript -e 'tell application \"Terminal\" to do script \"brightness 0\"' && sleep .5 && osascript -e 'quit app \"Terminal\"'"
}
],
"type": "basic"
}
]
},
{
"description": "f8 to 50% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f8"
},
"to": [
{
"shell_command": "osascript -e 'tell application \"Terminal\" to do script \"brightness .5\"' && sleep .5 && osascript -e 'quit app \"Terminal\"'"
}
],
"type": "basic"
}
]
},
{
"description": "f9 to 100% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f9"
},
"to": [
{
"shell_command": "osascript -e 'tell application \"Terminal\" to do script \"brightness 1\"' && sleep .5 && osascript -e 'quit app \"Terminal\"'"
}
],
"type": "basic"
}
]
},
Edit: After using some times I've noticed Brightness doesn't work properly (stopped working everytime the display goes to sleep). That's why I'm now using like this... (only goes to 0% or 100% but I think it's very simple & works for me)
{
"description": "f7 to 0% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f7"
},
"to": [
{
"shell_command": "for i in $(seq 16); do osascript -e 'tell application \"System Events\"' -e 'key code 145' -e ' end tell'; done"
}
],
"type": "basic"
}
]
},
{
"description": "f8 to down 50% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f8"
},
"to": [
{
"shell_command": "for i in $(seq 8); do osascript -e 'tell application \"System Events\"' -e 'key code 145' -e ' end tell'; done"
}
],
"type": "basic"
}
]
},
{
"description": "f9 to 100% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f9"
},
"to": [
{
"shell_command": "for i in $(seq 16); do osascript -e 'tell application \"System Events\"' -e 'key code 144' -e ' end tell'; done"
}
],
"type": "basic"
}
]
},
{
"description": "f3 to down 25% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f3"
},
"to": [
{
"shell_command": "for i in $(seq 4); do osascript -e 'tell application \"System Events\"' -e 'key code 145' -e ' end tell'; done"
}
],
"type": "basic"
}
]
},
{
"description": "f4 to up 25% brightnsess",
"manipulators": [
{
"from": {
"key_code": "f4"
},
"to": [
{
"shell_command": "for i in $(seq 4); do osascript -e 'tell application \"System Events\"' -e 'key code 144' -e ' end tell'; done"
}
],
"type": "basic"
}
]
}
brightness
binar? Seems to do exactly what you need?