get-monitor-brightness.sh 617 B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. # Get current monitor brightness for waybar
  3. MONITOR_SERIAL="6L1M413"
  4. VCP_CODE=10
  5. # Get current brightness
  6. current_output=$(ddcutil getvcp --sn "$MONITOR_SERIAL" "$VCP_CODE" 2>/dev/null)
  7. if [ $? -ne 0 ]; then
  8. echo '{"text": "N/A", "tooltip": "Monitor not available"}'
  9. exit 0
  10. fi
  11. # Parse current brightness
  12. current=$(echo "$current_output" | grep -oP 'current value\s*=\s*\K\d+')
  13. if [ -z "$current" ]; then
  14. echo '{"text": "N/A", "tooltip": "Could not read brightness"}'
  15. exit 0
  16. fi
  17. # Output JSON for waybar
  18. echo "{\"text\": \"$current%\", \"tooltip\": \"Monitor Brightness: $current%\"}"