3

Is there a way to trigger 3rd party apps to change to dark themes when Dark Mode is turned on in macOS Mojave?

Specifically, can I have PyCharm switch theme automatically to Darcula when I turn on Dark Mode?

LightsOff shows a list of all apps to theoretically selectively choose Light/Dark Mode for, but it has no effect on PyCharm. This is unfortunate especially since PyCharm is shown on the LightsOff homepage as if LightsOff can control its theme. Chrome, MATLAB and SourceTree are also 3rd party apps with a dark theme that show no effect. The only app I use which switched to a dark theme with LightsOff is Things.

  • PyCharm and other JetBrains IDE's are made entirely in Java, so any system setting you set will never work unless Jetbrains specifically adds support for it which probably won't happen. Besides PyCharm, which apps is LightsOff not working for? Can you please post a screenshot? – abc Oct 29 '18 at 16:46
  • I added more details. Noted about Java, this would also explain MATLAB. I don't know about the rest. If you can expand how the answer is no into an answer I can accept it. – buzjwa Oct 29 '18 at 20:32
2

Since PyCharm and other JetBrains IDE's are made in Java, they will not be able to use the native macOS Dark mode. Any system settings you apply also most likely won't affect Java applications, unless the developer specifically adds support for it, which probably won't happen due to the complexities of using system features with Java.(I've made some apps in Java, and it's currently impossible to use the macOS Dark Mode)

Many native apps will support Dark Mode without the developer having to do anything, but some that use custom UI views and controls, like Chrome, will need to add support for it manually. Dark mode support for Chrome is in progress(see here). SourceTree also uses custom controls and therefore doesn't support Dark Mode yet.

Edit: Chrome now fully supports dark mode.

2

I have come up with a (hacky) way to change themes in JetBrains editors using bash and AppleScript. An example for PyCharm would be something like:

#!/bin/bash
# Get the status of macOS dark mode and store as variable
isDarkModeOn=$(
    osascript <<EOT
    tell application id "com.apple.systemevents"
        tell appearance preferences
            set isDarkModeOn to dark mode
        end tell
    end tell
EOT
)

# Switch macOS dark mode on and off
# Equivalent to setting dark mode in System Preferences
osascript -e '
    tell application id "com.apple.systemevents"
        tell appearance preferences
            if dark mode is true then
                set dark mode to false
            else
                set dark mode to true
            end if
        end tell
    end tell
    '

# Change PyCharm theme
# Assumes default key mappings
# Switch to dark theme if dark mode was was off
if [ "$isDarkModeOn" = false ]; then
    osascript -e '
        if application "PyCharm" is running then
            -- switch focus to PyCharm
            tell application "PyCharm" to activate
            tell application "System Events"
                -- open Quick Switch Theme menu
                keystroke "`" using {control down}
                -- Select Look and Feel
                keystroke "5"
                delay 0.4
                -- Select Darcula
                keystroke "2"
            end tell
        end if
        '
# Switch to light theme if dark mode was on
else
    osascript -e '
        if application "PyCharm" is running then
          tell application "PyCharm" to activate
            tell application "System Events"
                keystroke "`" using {control down}
                keystroke "5"
                delay 0.4
                keystroke "1"
            end tell
        end if
        '
fi

I actually use it as a part of a larger script but the code above should work fine for PyCharm only (or any other JetBrains IDE, just replace application name). This is of course hacky. If you experience issues, I would suggest increasing/introducing delays between keystrokes like the delay 0.4 in the code above.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .