Open HmACK666 opened 5 years ago
@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.
@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
# ###########################################################################
#
#
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"
#
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
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
exec >> /var/log/LAB_LoginScript.log 2>&1 echo echo "=======" $SCRIPTNAME "running ======="
DisplayMirror="$4"
echo "mirroring on:" $DisplayMirror
MonitorProfile="$5"
echo "display profile enabled:" $MonitorProfile
MonitorBrightness="$6"
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"
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)
###########################################################################
#### 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=$!
if [ ! -e "$PROFILES_TOOL" ] || [ ! -e "$BRIGHTNESS_TOOL" ] || [ ! -e "$MIRROR_TOOL" ]; then jamf policy -trigger displaycalibratebinaries -user "$3" & sleep 15
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
/bin/chmod -R 777 /Library/ColorSync/Profiles
########################################### ####### Set monitor colour profile ########
if [ "$MonitorProfile" = "yes" ]; then echo "--- Setting Color Profile..."
#
#
#
echo "checking mirroring status"
MIRROR_STATE=$MIRROR_TOOL -q
echo "mirroring is:" $MIRROR_STATE
if [ "$MIRROR_STATE" == "on" ]; then
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
############################################## ###############################
if [ "$MonitorBrightness" = "yes" ]; then echo "--- Setting Monitor Brightness..." sleep 3
#### 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!"
"$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 ########
echo "checking mirroring status"
MIRROR_STATE=$MIRROR_TOOL -q
echo "mirroring state:" $MIRROR_STATE
if [ "$presentation" == "1" ]; then
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
#### 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
if [ "$DisplayMirror" = "yes" ]; then echo "--- Enabling Display Mirroring..." $MIRROR_TOOL -on fi
echo "Display Profile LoginScript complete"
/bin/kill $pid
rm -rf /tmp/mirrorrezX rm -rf /tmp/mirrorrezY rm -rf /tmp/unmirrorrezX rm -rf /tmp/unmirrorrezY
exit 0 `
@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.
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?