Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Written by chatgpt with my instruction
- #My use for this is to reset the colors on my equipment after it goes back to default from power loss
- # Default color is 500000 (dark red)
- default_color="500000"
- # Check if a color was passed as the first argument
- if [[ $1 =~ ^[0-9a-fA-F]{6}$ ]]; then
- color="$1"
- echo "Using custom color: $color"
- else
- color="$default_color"
- echo "No valid color provided, using default: $color"
- fi
- # Get the list of devices
- device_list=$(ratbagctl list)
- # Parse the device names (those containing a colon followed by a name)
- for device in $(echo "$device_list" | grep -oP '^\S+(?=:)' | uniq); do
- echo "Processing device: $device"
- # Get the list of LEDs for this device
- led_info=$(ratbagctl "$device" led get)
- # Extract LED numbers and current colors
- led_list=$(echo "$led_info" | grep -oP '(?<=LED: )\d+')
- led_colors=$(echo "$led_info" | grep -oP '(?<=color: )\S+')
- # Loop through each LED and check the current color
- i=1 # Index to keep track of current LED in the led_colors list
- for led in $led_list; do
- # Get the current color of the LED (nth entry from led_colors)
- current_color=$(echo "$led_colors" | sed -n "${i}p")
- # Compare current color with the target color
- if [[ "$current_color" == "$color" ]]; then
- echo "LED $led on $device is already set to $color. Skipping..."
- else
- echo "Setting LED $led on $device to color $color"
- ratbagctl "$device" led "$led" set color "$color"
- fi
- ((i++)) # Move to the next LED color
- done
- done
Advertisement
Add Comment
Please, Sign In to add comment