mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-01 20:28:16 +02:00
35 lines
1.0 KiB
Bash
Executable File
35 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Adjust the brightness on Apple Studio Displays and Apple XDR Displays using asdcontrol.
|
|
# omarchy:args=<+N%|N%-|N%>
|
|
# omarchy:examples=omarchy brightness display apple +5% | omarchy brightness display apple 5%- | omarchy brightness display apple 50%
|
|
|
|
if (( $# == 0 )); then
|
|
echo "Adjust Apple Display brightness by passing +5%, 5%-, or 100%"
|
|
else
|
|
step="$1"
|
|
if [[ $step =~ ^([0-9]+)%-$ ]]; then
|
|
step="-${BASH_REMATCH[1]}%"
|
|
fi
|
|
|
|
devices=()
|
|
for path in /dev/usb/hiddev* /dev/hiddev*; do
|
|
[[ -e $path ]] && devices+=("$path")
|
|
done
|
|
|
|
if (( ${#devices[@]} == 0 )); then
|
|
echo "No Apple Display HID device found"
|
|
exit 1
|
|
fi
|
|
|
|
device="$(sudo asdcontrol --detect "${devices[@]}" | grep -E '^/dev/(usb/)?hiddev' | cut -d: -f1 | head -n1)"
|
|
if [[ -z $device ]]; then
|
|
echo "No Apple Display HID device found"
|
|
exit 1
|
|
fi
|
|
|
|
sudo asdcontrol "$device" -- "$step" >/dev/null
|
|
value="$(sudo asdcontrol "$device" | awk -F= '/BRIGHTNESS=/{print $2+0}')"
|
|
omarchy-swayosd-brightness "$(( value * 100 / 60000 ))"
|
|
fi
|