Posted on 08-07-2020 08:39 AM
This is definitely random, but if you're ever curious about what percentage of your users have their Mac's appearance set to Light, Dark, or Auto, I wrote an extension attribute script that will display that info!
#!/bin/sh
# Displays the Appearance status for the currently logged-in user's account: Light, Dark, or Auto.
# Script will return the info as an extension attribute.
# Author: jwsherrod@mac.com
# Version 2.0 : 08-07-2020
loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
if [ -e "/Users/$loggedInUser/Library/Preferences/.GlobalPreferences.plist" ]; then
AppleInterfaceStyleVal=$(/usr/bin/defaults read /Users/$loggedInUser/Library/Preferences/.GlobalPreferences.plist AppleInterfaceStyle)
AppleInterfaceStyleSwitchesAutomaticallyVal=$(/usr/bin/defaults read /Users/$loggedInUser/Library/Preferences/.GlobalPreferences.plist AppleInterfaceStyleSwitchesAutomatically)
fi
if [ $AppleInterfaceStyleVal ]; then
echo "<result>$AppleInterfaceStyleVal</result>"
elif [ $AppleInterfaceStyleSwitchesAutomaticallyVal -eq 1 ]; then
echo "<result>Auto</result>"
else echo "<result>Light</result>"
fi
exit 0
Posted on 08-07-2020 07:51 PM
Neat trick, played around with the plist in Python. I suppose this is only for tracking what a user prefers since apps should handle this natively, but I came up with this
>>> from SystemConfiguration import SCDynamicStoreCopyConsoleUser
>>> from CoreFoundation import CFPreferencesCopyAppValue
>>> from Foundation import NSHomeDirectoryForUser
>>>
>>> user, uid, gid = SCDynamicStoreCopyConsoleUser(None, None, None)
>>> home = NSHomeDirectoryForUser(user)
>>> userfile = home + '/Library/Preferences/.GlobalPreferences.plist'
>>> keys = ['AppleInterfaceStyle', 'AppleInterfaceStyleSwitchesAutomatically']
# just loop and see what we get
>>> for k in keys:
... print(CFPreferencesCopyAppValue(k, userfile))
...
Dark
None
>>>
# test for None values
>>> for k in keys:
... result = CFPreferencesCopyAppValue(k, userfile)
... if result is not None:
... print(result)
...
Dark
>>>
Posted on 08-13-2020 12:58 PM
This is pretty cool! Thank you for sharing.