Change macOS Dock Icon with Dark Mode Change in Swift

Viewed 288

Xcode 11, Swift 5.1

I want to set a different dock icon for my macOS app depending on whether the user has dark mode enabled or not.

This is what I have in my app delegate's applicationDidFinishLaunching method:

if NSApp.effectiveAppearance.name == .darkAqua {
  NSApp.applicationIconImage = NSImage(named: "MacIconDark")
  print("dark")
}else{
  NSApp.applicationIconImage = NSImage(named: "MacIconLight")
  print("light")
}

But it always loads the icon I have defined in my project target no matter what. I'd also like to listen for dark mode changes and update my dock icon accordingly.

How do I dynamically update my app's dock icon?

0 Answers
Related