Tech Tip: Utility Method to Find Appearance Setting on Mac
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac
Published On: October 12, 2020
Mac users can set their system appearance to be in Light Mode, Dark Mode, or Auto. When designing an application, it can be helpful to know which appearance setting the Mac user uses and adjust the application interface to match accordingly.
Here is a utility method to find which mode is being used on the Mac machine. The appearance mode settings are stored in the .GlobalPreferences.plist file. The method uses Terminal to read the AppleInterfaceStyle and AppleInterfaceStyleSwitchesAutomatically keys in the file to determine the current appearance mode.
//================================================================= //METHOD NAME : MacAppearanceMode //DESCRIPTION: Checks if Mac is in Dark, Light, or Auto Mode //$out="Dark\n" if dark mode //$out="" if light or auto mode //$out2="" if light or dark mode //$out2="1\n" if auto mode //OUTPUT: // - $0: Returns "Dark", "Light", or "Auto" //================================================================= C_TEXT($0;$cmd;$in;$out;$err;$cmd2;$out2;$err2;$mode) $cmd:="defaults read -g AppleInterfaceStyle" $cmd2:="defaults read -g AppleInterfaceStyleSwitchesAutomatically" $in:="" LAUNCH EXTERNAL PROCESS($cmd;$in;$out;$err) LAUNCH EXTERNAL PROCESS($cmd2;$in;$out2;$err2) Case of : ($out="Dark@") $mode:="Dark" : ($out="") & ($out2="") $mode:="Light" : ($out="") & ($out2#"") $mode:="Auto" End case $0:=$mode |
C_TEXT($MacAppearance) $MacAppearance:=MacAppearanceMode |