Giter VIP home page Giter VIP logo

mac-keyboard-brightness's Introduction

Archived: Use https://github.com/EthanRDoesMC/KBPulse for Macs released after 2016


Control Mac Keyboard Brightness: kbrightness & dbrightness

Programmatically flash the keyboard lights and control display brightness on Macs. You can flash them to the beat of music, or use it for alerts and notifications.

This was inspired by @tcr's repo. This is also an alternative to the old iSpazz iTunes plugin, which no longer works. I had trouble finding any other easy-to-use binary for controlling keyboard brightness, so I made one.

Flashing keyboard gif Flashing display gif

Usage

  • blink is a shortcut to flash the keyboard lights [n] times for [t] seconds each time
  • kbrightness manages the keyboard backlight brightness
  • dbrightness manages the display backlight brightness
  • python3 audio.py flash the keyboard based on the audio input from your mic, makes it flash to the beat of music

Use blink in your shell scripts to alert you when things have succeeded or failed. e.g. wget https://example.com/large-file.mp4 && blink 2 or ./tests.py || blink 3 1

git clone https://github.com/pirate/mac-keyboard-brightness
cd mac-keyboard-brightness/

./kbrightness          # gets current keyboard brightness
# 0.286447
./kbrightness 0.85     # sets keyboard brightness to 85%

./dbrightness          # gets current display brightness
# 0.938477
./dbrightness 0.42     # sets display brightness to 42%
=======

./blink                # flash the keyboard lights once (good for subtle alerts, e.g. git pull && blink 2)
./blink 2              # flash the keyboard lights twice
./blink 10 0.1         # flash the keyboard lights 10 times, for 0.1 seconds each time
./blink 1000 0.01      # turn your keyboard into a disco strobe

=======

# Flash your keyboard to the beat of the music! (uses mic input)
brew install python3 pyaudio portaudio
pip3 install --upgrade pyaudio audioop
python3 audio.py

You should be able to download the repo and use the binaries without needing to recompile anything (tested on macOS Sierra, High Sierra, and Mojave).

Why?

It's fun. Here are some ideas:

  • make a bitbar menubar app to control keyboard brightness
  • make your keyboard lights flash for security alerts using Security Growler
  • make your keyboard flash right before your display is about to sleep
  • make your keyboard flash on incoming email
  • make your keyboard flash to the beat of music
  • make your keyboard flash when your boss's iPhone comes within bluetooth range

Advanced

If you want to write more advanced programs to update the brightness at higher frequencies (e.g. to make your keyboard flash to music), you can use the C functions directly.

  • setDisplayBrightness, getDisplayBrightness
  • setKeyboardBrightness, getKeyboardBrightness
  • getLightSensors: get ambient light sensor values, see @tcr's original repo

Compile each file individually with:

gcc -std=c99 -o kbrightness keyboard-brightness.c -framework IOKit -framework ApplicationServices
# OR
gcc -std=c99 -o dbrightness display-brightness.c -framework IOKit -framework ApplicationServices

Links

mac-keyboard-brightness's People

Contributors

pirate avatar yuzisee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mac-keyboard-brightness's Issues

Sets keyboard brightness only temporarily

I set the keyboard brightness to 0
./kbrightness 0
Press the power button to sleep, wake the mac up and then I get 100% brightness for keyboard.
Is this a desirable behavior? How to set key brightness permanently?

NOT WORKING PROPERLY Please PLEASE PLEASE PLEASE HELP!!!!

Ok, I was running the audio.py file and got this...

$ python3 audio.py
[+] Starting...
Traceback (most recent call last):
  File "audio.py", line 46, in <module>
    runloop(stream)
  File "audio.py", line 35, in runloop
    data = stream.read(CHUNK)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyaudio.py", line 608, in read
    return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9981] Input overflowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "audio.py", line 48, in <module>
    stream.stop_stream()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyaudio.py", line 524, in stop_stream
    pa.stop_stream(self._stream)
OSError: Stream not open

extra install steps to make audio.py run

Love this utility. Currently blinking along to Days of the New.

I had not previously installed many python libs so the README.md step was not enough to get audio.py to run.

Error:

$ pip3 install --upgrade pyaudio audioop
Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz
Collecting audioop
  Could not find a version that satisfies the requirement audioop (from versions: )
No matching distribution found for audioop

Fix:

brew install python3
brew install portaudio
pip3 install pyaudio

Then like the README says:

python3 audio.py

Refs:
https://stackoverflow.com/questions/31236194/installing-pyaudio-for-python3-on-osx

something wrong, after running a while

[+] Starting...
Traceback (most recent call last):
File "audio.py", line 46, in
runloop(stream)
File "audio.py", line 35, in runloop
data = stream.read(CHUNK)
File "/usr/local/lib/python3.6/site-packages/pyaudio.py", line 608, in read
return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9981] Input overflowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "audio.py", line 48, in
stream.stop_stream()
File "/usr/local/lib/python3.6/site-packages/pyaudio.py", line 524, in stop_stream
pa.stop_stream(self._stream)
OSError: Stream not open

kbrightness - Failed to connect to AppleLMUController getKeyboardBrightness() error

did git clone, and can't get kbrightness to work. it always gives this error

Failed to connect to AppleLMUController getKeyboardBrightness() error
 OS X High Sierra 10.13.4 (17E199) [or is called macOS High Sierra now?]
 Model Name:	MacBook Pro
  Model Identifier:	MacBookPro14,3
  Processor Name:	Intel Core i7
  Processor Speed:	3.1 GHz
  Number of Processors:	1
  Total Number of Cores:	4
  L2 Cache (per Core):	256 KB
  L3 Cache:	8 MB
  Memory:	16 GB
  Boot ROM Version:	MBP143.0175.B00
  SMC Version (system):	2.45f0

Keyboard brightness API removed by Apple on Macs after 2016 😭 (If you know of any new one, plz helpπŸ™)

macOS sierra version: 10.12.5 (16F73)
mbp 15-in, 2016

Display controls work fine but keyboard read and write operations fail:

$ ./dbrightness
0.650391
$ ./dbrightness .8
$ ./kbrightness
getLightSensors() error: failed to find ambient light sensor
getKeyboardBrightness() error
0.000000
$ ./kbrightness 1.0
getLightSensors() error: failed to find ambient light sensor
setKeyboardBrightness() error

I will update with more info when I have some time to debug this evening (and will pr if I find the issue).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.