暗黑模式是 macOS 的一项特性,它可以根据时间、日出和日落时间以及系统外观设置自动切换应用程序和操作系统界面的外观。在本文中,我们将讨论如何使用编程的方式启用和管理 macOS 的自动暗黑模式。
在 macOS 中,我们可以使用 AppleScript 编程语言来控制系统设置。AppleScript 是一种用于自动化 macOS 操作的脚本语言,它可以与系统和应用程序进行交互。以下是启用自动暗黑模式的 AppleScript 代码示例:
-- 启用自动暗黑模式
tell application "System Events"
tell appearance preferences
set dark mode to true
set automatic mode to true
end tell
end tell
上面的代码片段使用了 AppleScript 的语法,通过 System Events 应用程序和外观首选项来启用自动暗黑模式。set dark mode to true
将暗黑模式设置为启用,set automatic mode to true
则将其设置为自动模式。
要将上述代码保存为可执行的 AppleScript 脚本,可以使用 Script Editor 应用程序(位于 /Applications/Utilities/ 文件夹中)