Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to 'get', 'show' or 'query' current brightness #11

Open
HmACK666 opened this issue Jun 7, 2019 · 3 comments
Open

Unable to 'get', 'show' or 'query' current brightness #11

HmACK666 opened this issue Jun 7, 2019 · 3 comments

Comments

@HmACK666
Copy link

HmACK666 commented Jun 7, 2019

First off - awesome tool! I picked up on this while looking to set the 'optimise for:' option (in the Displays System Preference) via script.

More of a feature request - I currently get & set the brightness of displays with other scripts. Is display_manager going to be able to query & report the current brightness of a given display in the future?

@uurazzle
Copy link
Contributor

uurazzle commented Jun 7, 2019

@HmACK666 Thanks for the feedback, we appreciate knowing that sharing our tools is useful and beneficial to others in the community. Support for managing brightness is on our future plans. We are currently busy with other projects but will get back to this and other features and get them implemented.

@HmACK666
Copy link
Author

HmACK666 commented Jun 9, 2019

@uurazzle That's great to hear! I'm happy to assist testing on multiple hardware models if that helps.

The current login script I have set for our photography labs sets brightness, colour profile & resolution (for projectors).
I'm hoping to migrate tools used in my current login script to yours, where possible.
For those curious, I'll add it below:
`#!/bin/bash

Script Description

Run for all users, except admin at Login

###########################################################################

SETS CUSTOM COLOUR PROFILES FOR UP TO FOUR DISPLAYS

SETS CUSTOM BRIGHTNESS

Properties

set by Parameter Labels in script Options

comment below each option details the variables that can be used.

REQUIREMENTS

Script used to assign custom color profiles to displays:

PROFILES_TOOL="/Library/Scripts/org/SoA/customdisplayprofiles"

Binary used to set custom predefined brightness for displays:

BRIGHTNESS_TOOL="/Library/Scripts/org/SoA/brightness"

(used simply to mirror & unmirror displays on launch, no interaction: http://www.fabiancanas.com/open-source/mirror-displays/)

program used in the GUI also able to be referenced & run from the commandline:

MIRROR_TOOL="/Applications/Utilities/MirrorDisplays.app/Contents/MacOS/mirror"
REZ_TOOL="/Applications/Utilities/MirrorDisplays.app/Contents/Resources/cscreen"

VARIABLES

PROFILES_DIR=/Library/ColorSync/Profiles/Displays
BRIGHTNESS_PATH=/Library/ColorSync/Profiles/Displays/brightness_temp
BRIGHTNESS_VALUE=cat /Library/ColorSync/Profiles/Displays/brightness_temp | tr -d '[:space:]' | cut -c1-8
JAMFHELPER='/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper'
SCRIPTNAME="LAB_LoginScript-DisplayProfileCalibration2019"
ICC_FILE_PRINT=find $PROFILES_DIR -iname '*PRINT*' | tail -1
ICC_FILE_PROJECTOR=find $PROFILES_DIR -iname '*DataProjector*' | tail -1
ICC_FILE_EXT=find $PROFILES_DIR -iname '*EXTERNAL*' | tail -1

Get the system's UUID to set ByHost prefs

if [[ ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50 == "00000000-0000-1000-8000-" ]]; then
MAC_UUID=ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c51-62 | awk {'print tolower()'}
elif [[ ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50 != "00000000-0000-1000-8000-" ]]; then
MAC_UUID=ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62
fi

add to log started by main login script:

exec >> /var/log/LAB_LoginScript.log 2>&1
echo
echo "=======" $SCRIPTNAME "running ======="

DisplayMirror="$4"

yes or no

echo "mirroring on:" $DisplayMirror

MonitorProfile="$5"

yes or no

echo "display profile enabled:" $MonitorProfile

MonitorBrightness="$6"

yes or no

echo "monitor brightness enabled:" $MonitorBrightness

if [ -e /Library/Preferences/nz.ac.org.ProjectorSettings.plist ]; then
presentation=$(defaults read /Library/Preferences/nz.ac.org.ProjectorSettings.plist presentation)
if [ "$presentation" == "1" ]; then
echo " This computer is set as a presentation Mac"
echo " will read custom settings from /Library/Preferences/nz.ac.org.ProjectorSettings.plist"
#### define these settings here
res=$(defaults read /Library/Preferences/nz.ac.org.ProjectorSettings resolution)
m_res=$(defaults read /Library/Preferences/nz.ac.org.ProjectorSettings mirrored_resolution)
#### split X & Y resolutions for each string
resX=$(echo $res | cut -d "x" -f1)
resY=$(echo $res | cut -d "x" -f2)
m_resX=$(echo $m_res | cut -d "x" -f1)
m_resY=$(echo $m_res | cut -d "x" -f2)
#### specify refresh rates
refresh=$(defaults read /Library/Preferences/nz.ac.org.ProjectorSettings refresh)
m_refresh=$(defaults read /Library/Preferences/nz.ac.org.ProjectorSettings mirrored_refresh)

	echo "  projector X resolution specified: "$resX
	echo "  projector Y resolution specified: "$resY

	echo "  mirrored mode projector X resolution specified: "$m_resX
	echo "  mirrored mode projector Y resolution specified: "$m_resY

	echo "  projector refresh rate specified: "$refresh
	echo "  mirrored mode projector refresh rate specified: "$m_refresh
else
	echo "  this computer is a standard student Mac,"
    echo "  no custom resolutions to be applied"
fi

else
echo " no Projector Settings file present"
fi

export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
user=$(defaults read /Library/Preferences/com.apple.loginwindow.plist lastUserName)

###########################################################################

Script action

#### display message to user:
"/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" \
	-windowType hud \
	-title "Login Settings" \
	-description "Display Calibration..." \
	-icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/com.apple.led-cinema-display-27.icns" \
	-windowPosition lr &
pid=$!
Check that the required scripts/binaries exist

if not trigger a policy to install them

if [ ! -e "$PROFILES_TOOL" ] || [ ! -e "$BRIGHTNESS_TOOL" ] || [ ! -e "$MIRROR_TOOL" ];
then
jamf policy -trigger displaycalibratebinaries -user "$3" &
sleep 15
#### re-define tools
PROFILES_TOOL="/Library/Scripts/org/SoA/customdisplayprofiles"
BRIGHTNESS_TOOL="/Library/Scripts/org/SoA/brightness"
MIRROR_TOOL="/Applications/Utilities/MirrorDisplays.app/Contents/MacOS/mirror"
REZ_TOOL="/Applications/Utilities/MirrorDisplays.app/Contents/Resources/cscreen"
fi

Change permissions on /Library/ColorSync folder

so customer screen and printer profiles can be created

Change request for photography lab - 22 Feb 2006

/bin/chmod -R 777 /Library/ColorSync/Profiles

###########################################
####### Set monitor colour profile ########

if [ "$MonitorProfile" = "yes" ]; then
echo "--- Setting Color Profile..."

Using the customdisplayprofiles script, get details for up to 4 connected displays.

Displays reporting as "iMac" are treated as the main display & will have the "print" icc profile applied.

Displays reporting as "Panasonic" are treated as projectors & will have the "video" icc profile applied.

Any other displays will have an "external" icc profile applied (potential future use).

Display descriptions:

13" MacBook Pro: 'Color LCD'
20" external Cinema Display:
iMac dispalys: 'iMac'

may need to add extra criteria for the projectors (multiple models/names etc)
profiles set by the tool are unset if the Displays preference pane if loaded - maybe try to use the global option to load profiles?

check mirroring status of displays, if mirrored un-mirror to apply settings

echo "checking mirroring status"
MIRROR_STATE=$MIRROR_TOOL -q
echo "mirroring is:" $MIRROR_STATE

if [ "$MIRROR_STATE" == "on" ]; then
##### unmirror displays
echo "unmirroring displays.."
$MIRROR_TOOL -t
fi

for display in 1 2 3 4
   do
	displayquery=`$PROFILES_TOOL info -d "$display"`
	if [ "$displayquery" != "" ]; then
		$PROFILES_TOOL info -d "$display" | sed -e 's/^[ \t]*//' | sed 's/^[ \t]*//;s/[ \t]*$//' > "/tmp/display$display".log
	fi
	DeviceDescription=`$PROFILES_TOOL info -d "$display" | grep -s "DeviceDescription =" | sed -e 's/    DeviceDescription =//g' | sed -e 's/;//g'`
	case "$DeviceDescription" in
		*iMac*)
		#####ICC_FILE=`find $PROFILES_DIR -iname '*PRINT*'`
		if [ "$ICC_FILE_PRINT" != "" ]; then
			echo "match on $DeviceDescription setting $ICC_FILE_PRINT for display"
			$PROFILES_TOOL set -d "$display" -u any "$ICC_FILE_PRINT"
		else
			echo "no icc profile found for $DeviceDescription"
    		# display HUD UI error message
    		"$JAMFHELPER" -windowType utility \
        	-lockHUD \
			-heading "The main display is not color calibrated!" \
        	-description "Color & tone displayed on this screen is different to the color & tone encoded in your image files" \
    		-icon '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns' \
        	-button1 "OK" -defaultButton 1 &
		fi
		;;
		*PANASONIC*)
		##### set optimum resolution for projector
        echo " setting specified resolution for projector.."
		if [ "$presentation" == "1" ]; then
			# if refresh rate specified, use this
            if [ "$m_refresh" -gt "0" ]; then
				$REZ_TOOL -x "$resX" -y "$resY" -r "$refresh" -s 2
        	else
        		$REZ_TOOL -x "$resX" -y "$resY" -s 2
            fi
        fi
		if [ "$ICC_FILE_PROJECTOR" != "" ]; then
			echo "match on $DeviceDescription setting $ICC_FILE_PROJECTOR for projector"
			$PROFILES_TOOL set -d "$display" -u any "$ICC_FILE_PROJECTOR"
		else
			echo "no icc profile found for $DeviceDescription"
    		##### display HUD UI error message
    		"$JAMFHELPER" -windowType utility \
        	-lockHUD \
			-heading "The PANASONIC projector display is not color calibrated!" \
        	-description "Color & tone displayed on the projector is different to the color & tone encoded in your image files" \
    		-icon '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns' \
        	-button1 "OK" -defaultButton 1 &
		fi
		;;
		*EPSON*)
		#### set optimum resolution for projector
        echo " setting specified resolution for projector.."
		if [ "$presentation" == "1" ]; then
			# if refresh rate specified, use this
            if [ "$m_refresh" -gt "0" ]; then
				$REZ_TOOL -x "$resX" -y "$resY" -r "$refresh" -s 2
        	else
        		$REZ_TOOL -x "$resX" -y "$resY" -s 2
            fi
        fi
		if [ "$ICC_FILE_PROJECTOR" != "" ]; then
			echo "match on $DeviceDescription setting $ICC_FILE_PROJECTOR for projector"
			$PROFILES_TOOL set -d "$display" -u any "$ICC_FILE_PROJECTOR"
		else
			echo "no icc profile found for $DeviceDescription"
    		#### display HUD UI error message
    		"$JAMFHELPER" -windowType utility \
        	-lockHUD \
			-heading "The EPSON projector display is not color calibrated!" \
        	-description "Color & tone displayed on the projector is different to the color & tone encoded in your image files" \
    		-icon '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns' \
        	-button1 "OK" -defaultButton 1 &
		fi
		;;
		*)
		if [ "$ICC_FILE_EXT" != "" ]; then
			echo "match on $DeviceDescription setting $ICC_FILE_EXT for external display"
			$PROFILES_TOOL set -d "$display" -u any "$ICC_FILE_EXT"
		else
			echo "no icc profile found for $DeviceDescription" >/dev/null
		fi
		;;
	esac
    #### clean up tmp file so as not to cause permissions issues
    rm -rf "/tmp/display$display".log
done

fi

##############################################
###############################

Brightness setting

if [ "$MonitorBrightness" = "yes" ]; then
echo "--- Setting Monitor Brightness..."
sleep 3
#### Disable ambient light sensor on Mac
#### this stops the display brightness from auto changing
#### global setting, requires reboot to take effect
defaults write /Library/Preferences/com.apple.iokit.AmbientLightSensor "Automatic Display Enabled" -bool FALSE

##### From macOS High Sierra (10.13) the brightness setting changed to
##### /var/db/hidd/Library/Preferences/ByHost/com.apple.iokit.AmbientLightSensor.$MAC_UUID.plist
plistpath="/var/db/hidd/Library/Preferences/ByHost/com.apple.iokit.AmbientLightSensor.$MAC_UUID.plist"
defaults write "$plistpath" "Automatic Display Enabled" -bool FALSE

#### convert plist to xml to modify
sudo plutil -convert xml1 -o "/tmp/com.apple.iokit.AmbientLightSensor.$MAC_UUID.plist" "$plistpath"
plisttemp="/tmp/com.apple.iokit.AmbientLightSensor.$MAC_UUID.plist"
#### echo the original value
beforevalue=`sudo defaults read "$plisttemp" "Automatic Display Enabled"`
echo "before value: $beforevalue"
#### modify
sudo defaults write "$plisttemp" "Automatic Display Enabled" -bool false
#### echo the modified value
aftervalue=`sudo defaults read "$plisttemp" "Automatic Display Enabled"`
echo "after value: $aftervalue"
#### convert plist back to binary
sudo plutil -convert binary1 -o "$plistpath" "$plisttemp"

killall cfprefsd
#
BRIGHTNESS_VALUE_L=$BRIGHTNESS_TOOL -l | grep "brightness" | awk -F "brightness " '{ print $NF }'
echo "test live value: $BRIGHTNESS_VALUE_L">/dev/null

if [ "$BRIGHTNESS_VALUE_L" == "" ]; then
	echo "try another binary.."
	BRIGHTNESS_TOOL="/Library/Scripts/org/SoA/screenbrightness"
	BRIGHTNESS_VALUE_L=`$BRIGHTNESS_TOOL -l | grep "brightness" | awk -F "brightness " '{ print $NF }'`
	if [ "$BRIGHTNESS_VALUE_L" == "" ]; then
		echo "Hardware not compatible, exiting.."
        #### display HUD UI error message
        "$JAMFHELPER" -windowType utility \
        -lockHUD \
    	-heading "Error setting brightness!" \
        -description "hardware incompatible" \
        -icon '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns' \
        -button1 "OK" -defaultButton 1 &
		exit 1
	fi
else
	echo "Hardware compatible, continue..">/dev/null
fi

echo "brightness value:" $BRIGHTNESS_VALUE
if [ "$BRIGHTNESS_VALUE" = "" ]; then
echo "No brightness value!"
#### display HUD UI error message
"$JAMFHELPER" -windowType utility
-lockHUD
-heading "Error setting brightness!"
-description "no stored value for brightness"
-icon '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns'
-button1 "OK" -defaultButton 1 &
else
#### set brightness
$BRIGHTNESS_TOOL -l
$BRIGHTNESS_TOOL -d 0 -v "$BRIGHTNESS_VALUE"
fi
fi
sleep 3

#########################################
####### Enable Display Mirroring ########

####check mirroring status of displays
echo "checking mirroring status"
MIRROR_STATE=$MIRROR_TOOL -q
echo "mirroring state:" $MIRROR_STATE

if [ "$presentation" == "1" ]; then

Check to make sure the library and command-line API are both installed

if [[ -e /Library/Python/2.7/site-packages/display_manager_lib.py &&
-e /usr/local/bin/display_manager.py ]] ; then
/usr/local/bin/display_manager.py mirror enable ext0 main
else
exit 1
fi
#### set custom mirrored resolutions
#### if refresh rate specified, specify refresh..
if [ "$m_refresh" -gt "0" ]; then
echo " setting custom mirrored resolution for projector with refresh rate.."
$REZ_TOOL -x "$m_resX" -y "$m_resY" -r "$m_refresh" -s 2
else
echo " setting custom mirrored resolution for projector.."
$REZ_TOOL -x "$m_resX" -y "$m_resY" -s 2
fi
echo "--- Enabling Display Mirroring..."
$MIRROR_TOOL -on
fi

read 'global' display settings from JSS

if [ "$DisplayMirror" = "yes" ]; then
echo "--- Enabling Display Mirroring..."
$MIRROR_TOOL -on
fi

#-------------
echo "Display Profile LoginScript complete"
#-------------

kill user message

####killall jamfHelper

kill HUD notification

/bin/kill $pid

tidy up tmp files to prevent permissions issues

not required as of May 2019 - to be removed

rm -rf /tmp/mirrorrezX
rm -rf /tmp/mirrorrezY
rm -rf /tmp/unmirrorrezX
rm -rf /tmp/unmirrorrezY

Always exit with 0 status

exit 0
`

@uurazzle
Copy link
Contributor

@HmACK666 Thanks for the details on your environment usage and the example shell/bash script. Again, we are busy with other projects, but will add the features when we have time to focus on this project again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants