Archives

All posts for the month May, 2024

At my dayjob I often listen to music while working, and sometimes I’m doing video calls with my team. To help avoid disruption, I put an RGB LED on top of my cubicle wall and wrote a script to update the color based on my activity. Red indicates the camera is active, amber indicates I’ve got music going, otherwise green.

#!/bin/bash
#
# Monitor the camera and audio to set LED color
# if camera active --> RED
# else if audio active --> YELLOW
# else --> GREEN

exec 2> /dev/null

COLOR_OLD="#ABCDEF"
while :
do
  COLOR="#00FF00"
  if lsof /dev/video0 > /dev/null ; then
    COLOR="#FF0000"
  else
    AUDIO=`pacmd list-sink-inputs | grep -c 'state: RUNNING'`
    if [ "$AUDIO" == "1" ]; then
      COLOR="#FFAA00"
    fi
  fi

  # Only update blink1 if the color has changed
  #echo "\"$COLOR\" vs \"$COLOR_OLD\""
  if [ $COLOR != $COLOR_OLD ]; then
    echo "Color: $COLOR"
    blink1-tool --rgb "$COLOR" > /dev/null
    COLOR_OLD=$COLOR
  fi

  sleep 0.1

done