Skip to content

Instantly share code, notes, and snippets.

@TylerLeonhardt
Created August 8, 2019 07:27
Show Gist options
  • Select an option

  • Save TylerLeonhardt/4b87957ca96c498ad481e907a695445e to your computer and use it in GitHub Desktop.

Select an option

Save TylerLeonhardt/4b87957ca96c498ad481e907a695445e to your computer and use it in GitHub Desktop.
A function to update the macOS appearance to Dark or Light mode!
function Update-macOSAppearance {
param(
[parameter(Mandatory)]
[ValidateSet('Dark', 'Light')]
$Mode
)
$currentMode = defaults read -globalDomain AppleInterfaceStyle
$appleScriptCommand = 'osascript -e ''tell application \"System Events\" to tell appearance preferences to set dark mode to not dark mode'''
if ($Mode -eq 'Light' -and ($currentMode -eq "Dark")) {
iex $appleScriptCommand
}
if ($Mode -eq 'Dark' -and (-not $currentMode -eq "Dark")) {
iex $appleScriptCommand
}
}
@TylerLeonhardt

Copy link
Copy Markdown
Author

no matter what I do, I can't seem to get rid of the "error" text:

2019-08-08 00:24:06.183 defaults[67133:1182646]
The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist

It still works, I just can't seem to hide that text from showing up when querying defaults... may need to switch to AppleScript for the read as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment