LightKit

MacBook Light Sensor and Display/Keyboard brightness control


License
BSD-3-Clause
Install
pod try LightKit

Documentation

LightKit

License CocoaPods compatible Carthage compatible

Access the ambient light sensors, and control MacBook's display & keyboard brightness in Swift.

LightKit

Warning: While it should be safe to play with the backlight, I am not responsible for any damages made to a computer using this code.

Installation

# Podfile
pod "LightKit"

# Cartfile
github "maxmouchet/LightKit"

Usage

import LightKit
let lk = LightKit()! // May be nil if it failed to open I/Os.

Note : Most methods and properties are returning optional as I/Os requests may fail if sensors and controllers could not be found.

Ambient light sensors

let lightSensorsReadings = lk.lightSensors
print("Left sensor: \(lightSensorsReadings?.left).")
print("Right sensor: \(lightSensorsReadings?.right).")

Display

print("Display brightness is \(lk.displayBrightness)")
lk.setDisplayBrightness(0.8) // A value between 0 and 1.
lk.setDisplayPower(false) // Put display to sleep
lk.setDisplayPower(true) // Wake up display

Keyboard

print("Keyboard brightness is \(lk.keyboardBrightness)")
lk.setKeyboardBrightness(0.8) // A value between 0 and 1.