Switching Monitor and Keyboard Lids on MacBook with Ubuntu Text-Based UI

If you’re using Ubuntu on a MacBook and prefer a text-based user interface, you may want to control the state of the monitor and keyboard lids. We will provide commands to switch the monitor and keyboard lids on and off, allowing you to customize your MacBook experience.

Switching Monitor Lid

To turn the monitor lid off and disable the backlight, use the following command:

1
bash -c "echo 0 > /sys/class/backlight/intel_backlight/brightness;"

To turn the monitor lid back on and enable the backlight, execute this command:

1
bash -c "echo 1808 > /sys/class/backlight/intel_backlight/brightness;"

Switching Keyboard Lid

To turn off the keyboard lid backlight, enter the following command:

1
bash -c "echo 0 > /sys/class/leds/smc::kbd_backlight/brightness;"

To turn on the keyboard lid backlight, use this command

1
bash -c "echo 120 > /sys/class/leds/smc::kbd_backlight/brightness;"

Creating Aliases for Convenience

If you find yourself frequently using these commands, you can create aliases to simplify the process. Add the following lines to your shell’s configuration file (e.g., ~/.bashrc):

1
2
3
4
alias keyboard-off='bash -c "echo 0 > /sys/class/leds/smc::kbd_backlight/brightness;"'
alias keyboard-on='bash -c "echo 120 > /sys/class/leds/smc::kbd_backlight/brightness;"'
alias monitor-off='bash -c "echo 0 > /sys/class/backlight/intel_backlight/brightness;"'
alias monitor-on='bash -c "echo 1808 > /sys/class/backlight/intel_backlight/brightness;"'

Conclusion

With the provided commands and aliases, you can conveniently control the state of the monitor and keyboard lids on your MacBook running Ubuntu with a text-based user interface. Whether you prefer working in a dark environment or need the keyboard backlight for enhanced visibility, these commands will enable you to customize your setup to suit your preferences.

Remember to execute the commands or aliases based on your desired lid state, and feel free to adjust the values to achieve your desired brightness levels. Enjoy the flexibility and customization options that Ubuntu provides on your MacBook!

0%