Mac快捷指令之暗黑模式的切换

528 阅读1分钟

image.png

可能对于纯浅色党或者纯暗黑党用处不大

但是在实际工作中所接触到的一些办公软件良莠不齐,有些是没有完整支持暗黑模式或者尚未适配兼容暗黑模式的,一般来说强制浅色就好了,人性化一点就是既可以单独设置某一种模式,也可以跟随系统进行设置.

这里分享曾经遇到的坑,也算是一种解决方案,希望能帮到大家~

未兼容Mac暗黑模式的应用,单独设置该应用为浅色模式,需要指定bundleId

defaults write com.xxx.xxxapp NSRequiresAquaSystemAppearance true 

bundleId获取方式

  • 方法①
read /System/Applications/Xcode.app/Contents/Info.plist CFBundleIdentifier
  • 方法②
osascript -e 'id of app "Xcode"' 

如果是全局一键切换的话可以使用Alfred 或者做成快捷指令通过菜单栏一键点击实现toggle,也就是文章开头那种效果

#!/bin/bash

query=$1

# Check=`defaults read -g AppleInterfaceStyle`

if [ "$query" = "dark" ]; then
	dark='true'
elif [ "$query" = "light" ]; then
	dark='false'
else
	dark='not dark mode'
fi

Script="tell app "System Events" to tell appearance preferences to set dark mode to $dark"

osascript -e "$Script"

image.png