I don't know if it's Lion or a hardware feature, but on my MacBook Air, the system changes the keyboard lighting (and screen brightness) depending on the ambient brightness, which is detected by a sensor near the iSight lens at the top of the screen. In bright surroundings, the keyboard lighting is disabled and pressing F5 or F6 does nothing.
Preference locations
Some system-wide settings are in /Library/Preferences
, and some user settings are in ~/Library/Preferences
. I say "some" because I have found settings in these locations before, but have not done an exhaustive search. Also, this is what could be called an implementation detail. It's not documented publicly by Apple, is not intended for users to manipulate directly (by editing the .plist files), and the way it works could change without warning in a future version of OS X. The fact that Apple made ~/Library
hidden by default on Lion is a good indication that the contents of this directory are not intended to be modified by typical users. So, for best results, you should modify the settings indirectly through System Preferences itself.
Having said that, I changed the brightness of my iMac running 10.7.3, then went looking for changed plist files in the directories listed above. I couldn't find anything pertaining to screen brightness.
However, I was able to use Automator to record a workflow that opens System Preferences, goes to the Displays pref pane, and adjusts the brightness slider. This may be an easier and more reliable option for you. A quick Google search indicates that automator workflows can run from the command line, but I didn't try this.
I'll also add that one of my setups is a MacBook Air with a 30" cinema display. Setting the brightness to the same percentage on both (25% for example) does not mean that the brightness matches visually. You will likely need to choose different brightness levels for each display to get them to appear equally bright.
Monitoring filesystem usage by System Preferences
EDIT: The way you can see which plist files are accessed or modified while running System Preferences is to run a command like this in Terminal:
sudo fs_usage -w | grep "System Pref" | grep plist | grep -v "Info\.plist"
This command outputs a huge list of paths and files, some of which don't exist. File updates continued logging for a few seconds after I quit the app.
If you go this route, here's what I recommend:
- Dump the list to a textfile
- Eliminate duplicate paths
- Look at the files which have been modified. Files with states such as "stat64", "open", and "getattrlist" are just being opened for reading, but files with states of "chmod" or "rename" are being modified. I saw my ~/Library/Preferences/com.apple.systempreferences.plist file get renamed with an extension of .CvkFEbo, which I believe is the system's way of performing an atomic file write (write the entire file under a different name, and if that is successful, rename it to the original filename).
Unfortunately, I still didn't turn up anything regarding a screen brightness setting persisted to disk, but I have only lightly skimmed the fs_usage results to now.
Command-line tool to control brightness
I found an article that lists source code for controlling screen brightness on OS X using the CoreGraphics framework. The article is a little over two years old, and I haven't tried it myself, but it may be useful to you. There are simple compiling instructions posted at the end.
Best Answer
Short answer, TLDR: No, a simple script will not suffice for what you are trying to do. But ...
You will have better luck using a third party like this one: https://github.com/pirate/mac-keyboard-brightness. His code can take user input and manipulate the keyboard for you. But I am not sure if this was tested in Mojave but you are welcome to try.
Long Answer, for the curious:
Certain system settings or running hardware tasks on a Mac are initiated and ran with kernel extensions and continue to run with the
kextd daemon
. What drivers are for Windows are how kernel extensions are for Mac OS. Without kernel extensions your Mac OS would not boot properly.You can safely test with your sound on your Mac using information about removing kexts here, but be sure to back up your files: http://osxdaily.com/2012/05/30/how-to-completely-disable-audio-sound-in-mac-os-x/
Take a look the code written there by Pirate, in his code in keyboard-brightness.c he does a good job dissecting the Mac. You can see how a bit more complex your script would be if you tried to tackle this through code. A simple bash script would not suffice.
In Pirate's code you can see that he accesses the keyboard light with the Foundation framework and the IOKit framework, written in Objective C/C++. If you are comfortable with this language then you should try to dabble more with his code.
Why running defaults didn't catch anything? The reason
defaults
doesn't show anything is becausedefaults
is meant to edit plist files only.How can I see my kernel extensions? You can see a full list of kernel extensions currently running in terminal with the following command:
You can also see a list of all your installed kernel extensions under:
In terminal you can see which keyboard kext file you have by running grep:
I do not have a laptop, but I am safely assuming you will also have a keyboard kext file that will look similar to mine:
Where can I learn more about the IOFramework? https://developer.apple.com/documentation/iokit?language=objc. On Pirate's git page you can see he also wrote his code in swift4, which might be easier to understand. You can switch back and forth from ObjC and Swift language types on the Apple Developer Page.
I hope this answer was useful to you.