How can I toggle the system dark mode from Terminal without using AppleScript? I have already searched things like "zsh toggle dark mode" and "terminal set dark mode mac", but I can't find relevant results. Is there any way to do this? I'd like to do it without AppleScript unless it's absolutely necessary.

2 Answers 2


As far as I'm aware, there's no way to do this without AppleScript, but you can do it in one line using it:

osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to not dark mode'

From https://brettterpstra.com/2018/09/26/shell-tricks-toggling-dark-mode-from-terminal/


Make sure all documents in other apps are saved and that other apps are closed, because you should restart your Mac at the end of this.

  1. Open Terminal.

  2. Run sudo defaults write /Library/Preferences/.GlobalPreferences.plist _HIEnableThemeSwitchHotKey -bool true

    (👆you can copy/paste this into your Terminal command line if you prefer).

  3. Because you're entering a sudo command, macOS will prompt you to enter your administrator password.. Enter it and hit return.

  4. Quit the Terminal app.

  5. Restart your Mac.


You must log in to answer this question.

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