Is there a way to use an Apple Script to control the brightness of the backlit keyboard on a Macbook?
The backlit keys are the F5
and F6
.
Edit:
Based on the suggestion of @Clark
I tried the follow, but it does not work.
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to key code 96"];
[run executeAndReturnError:nil];
Any suggestions?
Manually adjust keyboard backlighting or turn it off . In Control Center, click Keyboard Brightness, then drag the slider. In the Touch Bar, expand the Control Strip, then tap the increase brightness button or the decrease brightness button . To turn backlighting off, touch and hold.
Amit Singh has a chapter on how to do this from C.
https://web.archive.org/web/20200103164052/https://osxbook.com/book/bonus/chapter10/light/
It'd be easy to compile the sample code on that page and call it from Applescript.
To make Applescript type a function key you have to use the key code. The key codes fore the function keys are:
To type one do something like this:
tell application "System Events" to key code 96
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With