How to change Python menu bar app logo black and white based on Mac menu bar light or dark?

173 views Asked by At

I want to make a Python menu bar application using the rumps package, but I want to make my menu bar logo change from black and white based on the Mac menu bar color, is there any way to accomplish this using rumps? Or if there isn't a way is it possible to do it through another Python package?

MacOS: 12.0.1 Python: 3.9.8

1

There are 1 answers

0
DaveL17 On

I don't know of a package that can read/register macOS theme changes dynamically, but you can query the active theme directly using defaults read -g AppleInterfaceStyle:

import subprocess

command = "defaults read -g AppleInterfaceStyle"
result = subprocess.run(command, shell=True, capture_output=True, text=True)

if result.stdout.rstrip() == "Dark":
    # Dark Mode
else:
    # Light Mode

This approach assumes your client has the appropriate permissions to access system information and run system commands.