Sep 5, 2025 macos · swift · appearance · dark-mode

A Swift oneliner to detect Dark mode

The old defaults read -g AppleInterfaceStyle trick is unreliable on Sequoia. Sometimes the key is missing, sometimes it only shows Dark. I switched to Swift and asked the system directly.

Drop this into ~/bin/appearance.swift:

#!/usr/bin/env swiftc -o /Users/elia/bin/appearance

import AppKit

print(
  NSApplication.shared.effectiveAppearance.name.rawValue.contains("Dark") ? "Dark" : "Light"
)

Make it executable and build it once:

chmod +x ~/bin/appearance.swift
~/bin/appearance.swift

That compiles a tiny binary at ~/bin/appearance. From then on:

appearance # => Dark

prints Dark or Light instantly. Edit the .swift and rerun it any time to rebuild in place. Clean, fast, and it works on Sequoia.