2

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%.

5
  • btw also any shell command would be great help Commented Mar 26, 2023 at 17:48
  • Have you seen apple.stackexchange.com/a/127258/150109, does it work for you? Just bind that to a keyboard shortcut.
    – user150109
    Commented Mar 26, 2023 at 18:17
  • yeah I've seen that @theonlygusti but it has lots of complication/limitations as I read on the Github repo Commented Mar 26, 2023 at 18:21
  • Did you try the brightness binar? Seems to do exactly what you need?
    – nohillside
    Commented Mar 26, 2023 at 19:41
  • If you meant the thing @theonlygusti have mentioned. I'm not actually confident about the app/repo Commented Mar 26, 2023 at 19:55

1 Answer 1

0

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"
                        }
                    ]
                }

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