Skip to content
Proyectos

pirate/mac-hardware-toys

Ver en GitHub

Acerca de

🔆 Controla mediante programación el brillo del teclado y la pantalla del Mac, el acelerómetro y el giroscopio, el ángulo de la tapa, la luminosidad ambiental, la velocidad del ventilador, el micrófono, el altavoz y mucho más, como si fueran módulos de un sintetizador modular conectados mediante tuberías de shell.

Herramientas de desarrollo

Cómo se miden estas cifras

Crecimiento de estrellas medido

in 24h
0
in 7 days
0
in 15 days
+2
in 1 month
+2

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

🎛️ CLIs to Get/Set/Stream Mac Hardware Outputs & Sensors Inputs


Modern MacBook Pros are full of interesting hardware: lid-angle and ambient-light sensors, microphones, undocumented MEMS accelerometers and gyroscopes, plus fast controls for keyboard/display brightness, speakers, fans, and more.

This repo exposes that hardware as small, fast, composable Unix CLIs backed by Apple’s private APIs.

Screenshot 2026-11-30 at 11 11 50 AM

Play with the interactive site.


Quickstart

# recommended: install the suite with uv
uv tool install mac-hardware-toys

# show FFT + more info about current motion
accelerometer | visualizer

# pulses your keyboard lights to the beat
microphone | heartbeat | keyboard-brightness

# or get/set raw values directly, and more...
keyboard-brightness --help

Use --help on any command to see its sensor, signal, or hardware controls.

  • 💡 Flash your ⌨️ keyboard lights + play a sound when a background processes completes
  • 🎵 Pulse your fans in sync with some musc playing ambiently 🎵 music bpm
  • ❤️ Pulse your screen brightness in sync with your heart, detecting your pulse from wrists resting on laptop (via accelerometer)
  • 🔬 Get/Set/Stream accelerometer+gyroscope+microphone/etc. data as simple float32 samples or --json, or...

By default when used in pipes, commands represent signals as an audible 🎼 mono audio tone, expressed as a byte stream.

🎤 read realtime sensor feeds represented as sine waves
🎛️ mix/filter/transform those sine waves to shape them
🔊 emit piped realtime signal to speakers/any other hw output


[!TIP] Some truly wild things are possible now that you can pipe together anything on your Mac...
🎷 Share your craziest combos!


Flashing keyboard gif Flashing display gif

Screenshot 2026-02-20 at 11 19 36 PM

Examples

# flash your screen according to your microphone input
microphone | screen-brightness

# play a sine wave tone based on your screen lid-angle
lid-angle | speaker
# play the trackpad or print each touch’s ID, coordinates, frequency, and volume
trackpad-xy --low-hz 110 --high-hz 880 | speaker
trackpad-xy --json

# snap each trackpad tone to the C major pentatonic scale
trackpad-xy | autotune --scale pentatonic --root C | speaker

# play along with a metronome (bash or zsh)
mix <(trackpad-xy) <(metronome 120) | speaker

# flash the keyboard according to your heartbeat (keep your wrists on palm rests)
accelerometer | metronome | keyboard-brightness

# blink the Caps Lock LED on each beat, or pulse it directly
metronome 120 | capslock-light
capslock-light --pulse 3 --on-time=0.2 --off-time=0.2

# see more detail about any given signal by piping it into visualizer
microphone | visualizer
sine 1000 | visualizer
gyroscope | tee >(speaker) | visualizer

Tools

For sensors with multiple dimensions, choose what drives each tone with --pitch and --volume. For example, trackpad-xy --pitch=y --volume=x | speaker swaps the touch axes. Run a sensor in several pipelines to map the same movement more than one way. Each command lists its choices in --help.

accelerometer

Stream acceleration along X, Y, Z, or their combined magnitude. Select --pitch and --volume to play the axes as a tone.

accelerometer --pitch=x --volume=mag | speaker

airpods-accelerometer

Play the acceleration of your head as you move while wearing motion-capable AirPods.

airpods-accelerometer --pitch=y --volume=mag | speaker

airpods-gyroscope

Play how quickly you turn your head, measured in degrees per second by motion-capable AirPods.

airpods-gyroscope --pitch=z --volume=x | visualizer

ambient-light

Play the light falling on the display bezel. With --color-aware, light color controls pitch and illuminance controls volume.

ambient-light --color-aware | speaker

camera-motion

Turn changes between successive camera frames into a tone. More movement raises its pitch and volume.

camera-motion | screen-color

gyroscope

Turn the MacBook’s roll, pitch, or yaw into a tone as you tilt the lid and base together.

gyroscope --pitch=roll --volume=yaw | speaker

latency-bandwidth

Hear network latency as pitch and interface traffic as volume. Faster replies raise the pitch and more traffic raises the volume.

latency-bandwidth --pitch=latency --volume=rx | visualizer

lid-angle

Opening and closing the lid changes the tone’s pitch and volume.

lid-angle | speaker

lid-magnetic-flux

Stream the raw magnetic reading from the lid sensor.

lid-magnetic-flux --json

microphone

Capture mono audio from a microphone. Use --list-devices to find the input you want.

microphone | autotune | speaker

power-sensor

Play the Mac’s system or GPU power draw in watts. Each can control a different part of the tone.

power-sensor --pitch=gpu --volume=system | visualizer

sine

Generate a mono sine wave at the given frequency in hertz.

sine 440 | speaker

temp-sensor

Play temperatures from the Mac’s thermal probes. Run temp-sensor --list to see their names and readings in °C.

temp-sensor | visualizer

trackpad-force

Press harder on a Force Touch trackpad to raise the tone. Map total force and the number of fingers independently.

trackpad-force --pitch=fingers --volume=force | speaker

trackpad-xy

Play one tone per touch. Slide right for higher pitch and up for more volume.

trackpad-xy --low-hz 110 --high-hz 880 | speaker

wifi-signal

Play the Wi-Fi signal strength and noise measured by the radio. Choose which dBm reading controls each part of the tone.

wifi-signal --pitch=rssi --volume=noise | speaker

autotune

Tune incoming pitches to the nearest notes in a scale. Choose its root with --root.

trackpad-xy | autotune --scale pentatonic --root C | speaker

bandpass <low_hz> <high_hz>

Pass the part of a signal between two frequencies.

accelerometer | bandpass 0.8 3 | visualizer

frequency-shift <factor>

Multiply the frequencies in a signal. A factor of 2 moves a tone up one octave.

sine 220 | frequency-shift 2 | speaker

heartbeat

Estimate beats per minute from a signal. Rest your wrists on the palm rests to pick up your pulse with the accelerometer.

accelerometer | bandpass 0.8 3 | heartbeat

metronome [bpm]

Generate beat pulses at a set tempo, or pipe in a signal to follow its beat.

metronome 120 | capslock-light

mix

Add mono streams together. Give each source its own file or pipe, or use - for stdin.

mix <(trackpad-xy --pitch=y) <(trackpad-xy --pitch=x) | speaker

volume-shift <gain>

Multiply the signal amplitude by a gain. A gain of 0.5 halves the amplitude.

microphone | volume-shift 0.5 | speaker

capslock-light

Light the built-in Caps Lock key when the signal crosses a threshold. Set the LED directly with --set 0 or --set 1.

metronome 120 | capslock-light

fan-speed

Map a signal to fan RPM. Use --alternate to switch between fans on successive beats.

metronome 120 | fan-speed --alternate --input-map beat

keyboard-brightness

Drive the keyboard backlight from a signal or pulse it a set number of times.

keyboard-brightness --pulse 15 --on-time=0.2 --off-time=0.2

magsafe-led

Flash the MagSafe connector LED green or amber when a signal crosses the threshold. Amber takes priority when both colors are active.

metronome 120 | magsafe-led --color amber

screen-brightness

Drive the display backlight from the strength of a signal. Set a fixed percentage with --set.

microphone | screen-brightness

screen-color

Show pitch as hue and signal level as brightness. Concurrent pipelines blend their colors in one window.

microphone | screen-color

speaker

Play mono audio through the default output. Independent speaker pipelines play together.

sine 220 --seconds 2 | speaker &
sine 330 --seconds 2 | speaker

trackpad-vibration

Drive the Force Touch motor with the incoming pitch and signal strength, or generate a fixed number of pulses.

trackpad-xy --low-hz 110 --high-hz 880 | trackpad-vibration

visualizer

Watch waveform, spectrum, and level in the terminal. Signals sent to the same terminal share a display.

microphone | visualizer

Open a mono signal in soundview or the iTunes Classic Visualizer. Both commands print the local viewer URL to stderr.

microphone | soundview
trackpad-xy | itunes-visualizer

Example Usage

Heartbeat from accelerometer:

accelerometer | bandpass 0.8 3 | heartbeat

Ambient light as signal source:

ambient-light | visualizer

Lid angle as JSONL:

lid-angle --json

Gyroscope fused orientation as JSONL:

gyroscope --pitch roll --volume yaw --json

Music-reactive keyboard + speakers:

microphone --rate 44100 \
  | tee >(keyboard-brightness --send-hz 30 --fade-ms 20) \
  | volume-shift 0.8 \
  | speaker

Metronome to speakers:

metronome 120 | speaker

Auto-follow metronome from mic input, emits a metronome tone in sync with the beat of whatever audio is playing:

microphone | metronome | speaker

Auto-follow metronome from accelerometer, driving keyboard pulses:

accelerometer | metronome | keyboard-brightness

Metronome driving keyboard pulses:

metronome 120 | keyboard-brightness

Heartbeat telemetry while still driving keyboard brightness:

accelerometer | heartbeat | keyboard-brightness

Set keyboard backlight to 100% and exit:

keyboard-brightness --set=100

Pulse keyboard 5 times (1.2s on / 5.5s off) at 100%:

keyboard-brightness --pulse=5 --on-time=1.2 --off-time=5.5 --set=100

Vibrate the trackpad 15 times (0.2s on / 0.2s off):

trackpad-vibration --pulse 15 --on-time=0.2 --off-time=0.2

Drive trackpad vibration from sensors or metronome pulses:

microphone | trackpad-vibration --gain 4 --level 0.5
accelerometer | metronome | trackpad-vibration
trackpad-xy --low-hz 110 --high-hz 880 | trackpad-vibration

Set screen brightness to 40% and exit:

screen-brightness --set=40

Pulse screen brightness 3 times:

screen-brightness --pulse=3 --on-time=1.2 --off-time=5.5 --set=100

Metronome driving fan pulses:

metronome 120 | fan-speed --send-hz 4 --alternate --input-map beat --min-frac 0.30 --max-frac 0.70

Slow sine fan sweep (sync L/R):

sine 0.1 | fan-speed

One source, multiple sinks:

accelerometer \
  | bandpass 0.8 3 \
  | tee >(keyboard-brightness) \
  | frequency-shift 1000 \
  | volume-shift 0.8 \
  | tee >(speaker) \
  | visualizer

Development Setup

git clone https://github.com/pirate/mac-hardware-toys
cd mac-hardware-toys

uv sync
source .venv/bin/activate

Stdio Audio Format

The default stream format is MSIG1:

  • header: MSIG1 <sample_rate_hz>\n
  • payload: little-endian float32 mono samples

Sources write MSIG1 by default. Use --raw-output to omit the header. Consumers accept MSIG1 by default or --raw-input --rate <hz> for headerless samples. Filters accept both options independently. Sample rates may be fractional. Choose frequencies below half the sample rate.

sine 2 --rate 200 --raw-output | bandpass 0.8 3 --raw-input --rate 200 | heartbeat --json
metronome 120 --raw-output | capslock-light --raw-input --rate 44100

Sensor tone sources scale their frequency range together when the upper tone reaches half the requested sample rate. speaker --device-rate sets the separate playback rate. heartbeat --json writes estimates to stdout even when redirected.


Why?

It's fun. Here are some ideas to get started:

  • 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

Related Projects

Explorar proyectos relacionados

Cargando…