swiftDialog
swiftDialog copied to clipboard
Support for dark mode with Icon
I would love to be able to specify a specific icon for dark mode. We've found that our icon/logo does not look great on either one or the other.
Either specify in config or to use the right icon based on the names of the file.
Good suggestion. I currently handle this when using most dialoging tools, whether swiftDialog or others, by having 2 icons in place and detecting the "color mode" for the OS of the current user and then assigning the appropriate icon as the variable.
Example:
#!/bin/zsh
logged_in_user=$(/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ {print $3}')
icon_base64_dark="<base64 string of icon data goes here>"
icon_base64_lite="<base64 string of icon data goes here>"
/bin/echo "$icon_base64_dark" | /usr/bin/base64 --decode > /path/to/icondark.png
/bin/echo "$icon_base64_lite" | /usr/bin/base64 --decode > /path/to/iconlite.png
os_color_mode=$(/usr/bin/defaults read /Users/$logged_in_user/Library/Preferences/.GlobalPreferences.plist AppleInterfaceStyle)
if [ "$os_color_mode" = "Dark" ]; then
icon_path="/path/to/icondark.png"
else
icon_path="/path/to/iconlite.png"
fi
Then in the rest of the script you just use $icon_path
as the variable for the --icon
flag.
That said, having a built in way to have it use the appropriate icon would be cool.
I've had a think about how this would be implemented and have settled on one of two options:
-
have
--icon
accept a dark and light path such as--icon dark=/path/to/image_dark.png,light=/path/to/image_light.png
.--icon /path/to/image.png
would also continue to work as it does currently. -
have dialog auto pick. e.g.
--icon /path/to/image.png
would look forimage.png
image_light.png
andimage_dark.png
and use whichever exists and is appropriate. (would also work in reverse, so passing inimage_light.png
would make it also look forimage_dark.png
andimage.png
)
option 1 is less development effort but I like the simplicity for the admin with option 2.
@mm2270 that method is pretty cool and if you don't mind I might mention that in the wiki for the time being.
@bartreardon Yes of course you can use that in the wiki.
Nice call! Looks like this works in python:
from Foundation import NSBundle
def is_dark_mode():
appearanceBundle = NSBundle.bundleWithPath_(
"/System/Library/PreferencePanes/Appearance.prefPane"
)
appearanceShared = appearanceBundle.classNamed_("AppearanceShared")
app = appearanceShared.sharedAppearanceAccess()
if app.theme() == 1:
return False
else:
return True
if is_dark_mode():
content["icon"] = "dark_icon.png"
else:
content["icon"] = "light_icon.png"
That can work for now.
Updated the wiki for the time being
closing this as wontfix.
if dark/light icons are important then the admin can supply the logic to handle it.