Skip to content

Useful script for controlling multiple Apple Cinema Displays from keyboard shortcuts.... #6

@p-sims

Description

@p-sims

If you have acdcontrol working and you install bash script as:
/var/usrlocal/bin/acdbrightness

And setup keyboard shortcuts that run /usr/local/bin/acdbrightness + and /usr/local/bin/acdbrightness -:

Image

Then you can have brightness on keyboard like you would in MacOS X

Script:

# bin/bash

# This script was written by Peter in Jan 2025 and can be fired from gnome custome keyboard shortcuts
# /dev/usb/hiddev2 is where applecinema display appears on Framework laptop running projectbluefin fedora atomic whith displayport connected to thinkpad USB4 dock
# This script was tested when install in /usr/local/bin/ as root:root with -rwxr-xr-x. permissions.
# it can be run by custom gnome shortcut using "/usr/local/bin/acdbrightness +" as the command

# 24" has product id 'Product=0x9236'
# 27" has product id 'Product=0x9226'
# Other models will need adding to case statement below to populate max brightness and step.

verbose=false

case $1 in
	*help*)
		echo "This script will find Apple Cinema Displays (ADCs) in /dev/usb/hiddev* and either report of set brightness using acdcontrol from https://github.com/warvariuc/acdcontrol ";
		echo "Pass - to decress brightness, + to inrease brightness, or v (verbose) to print debug info";
		exit 0;;
	-v)
		verbose=true;
		set -- $2;
		echo "Script Arguements: $@";;
esac 

declare -A Display=(["0"]="/dev/usb/hiddev")
NumADCs=0

#Display[display0type]="24"

#echo "Display (keys): ${!Display[@]}"
#echo "Display (values): ${Display[@]}"
#echo "Length: ${#Display[@]}"

#exit 0

for x in $(seq 0 9); do
#	echo $(/usr/local/bin/acdcontrol "${Display[0]}$x"v -s)
	check=$(/usr/local/bin/acdcontrol "${Display[0]}$x" -s 2>&1 | tr -d '\n');
	if $verbose; then echo "${Display[y0]}$x ==> $check"; fi
    if [[ $check  == *"unsupported"* ]]; then
	if $verbose; then echo ">>> ${Display[0]}$x is not a Apple Cinema Display!"; fi
    elif [[ $check  == *"BRIGHTNESS"* ]]; then
	NumADCs=$((NumADCs+1));
	Display[$NumADCs]="${Display[0]}$x";
	Display[${NumADCs}type]=$(/usr/local/bin/acdcontrol --detect "${Display[0]}$x" | awk -F'Product=|[[]' '{printf "%s",$2}');
	case ${Display[${NumADCs}type]} in
		"0x9236")				# 24"
			Display[${NumADCs}max]=255;
			Display[${NumADCs}step]=16;
			;;
		"0x9226")				# 27"
			Display[${NumADCs}max]=1023;
			Display[${NumADCs}step]=64;
			;;
		*)
			echo "Error - Display type not found: $Display[${NumADCs}type]"
	esac	
	
	echo "+++ Apple Cinema Display $NumADCs found as '${Display[$NumADCs]}' type=${Display[${NumADCs}type]} +++";
    else 
	if $verbose; then echo "#########  Error whilst checking x=$x! ############"; fi 
#	echo " "
    fi
done

#exit 0

if [ $NumADCs -eq 0 ]; then
	echo "!!! No Apply Cinema Display's Found !!!"
	exit 1
fi

if $verbose; then echo "¦¦¦¦¦¦ ACD Lists = ${Display[*]}"; 
	echo "Displays (keys): ${!Display[@]}"
	echo "Displays (values): ${Display[@]}"
	echo "Length: ${#Display[@]}"
fi 


for x in $(seq 1 $NumADCs); do
	if $verbose; then echo $(/usr/local/bin/acdcontrol ${Display[$x]} |  cut -d '=' -f 2 -s); fi
	Display[${x}brightness]=$(/usr/local/bin/acdcontrol ${Display[$x]} |  cut -d '=' -f 2 -s)
	echo ${Display[${x}brightness]} "is brightness of Display $x"

	case $1 in
		"")	exit 0;
			;;
		-)
			if [[ ${Display[${x}brightness]} -ge ${Display[${NumADCs}step]} ]];
			then
				Display[${x}brightness]=$(( ${Display[${x}brightness]} - ${Display[${x}step]} ));
			else
				Display[${x}brightness]=0;
			fi;
			;;
		+)
	                if [[ ${Display[${x}brightness]} -lt $(( ${Display[${x}max]} - ${Display[${x}step]} )) ]];
	                then
	                        Display[${x}brightness]=$(( ${Display[${x}brightness]} + ${Display[${x}step]} )); 
	                else
	                        Display[${x}brightness]=${Display[${x}max]};                             
	                fi;
			;;
	        =)
			Display[${x}brightness]=$2;
		        ;;
		*)
			echo "invalid input";
			exit 1;
			break;;
	esac # signals the end of the case statement to the kernel

	echo "New brightness: ${Display[${x}brightness]}"
done

for x in $(seq 1 $NumADCs); do
	if $verbose; then echo /usr/local/bin/acdcontrol ${Display[$x]} $brightness	-s; fi	
	/usr/local/bin/acdcontrol ${Display[$x]} ${Display[${x}brightness]}	-s	

	if $verbose; then /usr/local/bin/acdcontrol ${Display[$x]} |  cut -d '=' -f 2 -s; fi
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions