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
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.
Open Terminal.
Run
sudo defaults write /Library/Preferences/.GlobalPreferences.plist _HIEnableThemeSwitchHotKey -bool true
(👆you can copy/paste this into your Terminal command line if you prefer).
Because you're entering a
sudo
command, macOS will prompt you to enter your administrator password.. Enter it and hit return.Quit the Terminal app.
Restart your Mac.
-
1it's fine to quote the relevant part from a different source, but then at least include that you've done so with a link to where you found it Feb 28, 2022 at 16:35