以编程方式更改 macOS Mojave 强调色

Programmatic change macOS Mojave accent color

我正在编写一个允许用户设置 macOS Mojave 的强调色的应用程序。

我的第一次尝试是使用 AppleScript。但我意识到 API 还不是最新的:

带下划线的 API 有效,但它只有 2 个颜色选项,而新的 OS 有 8 个。

我想知道是否有任何解决方法。语言不限,只要行得通。谢谢

这是一个完整的 AppleScript 解决方案,它允许用户选择浅色或深色模式、高亮颜色和强调色。如果用户在突出显示颜色选项中选择“其他”,脚本可能会抛出错误,因为我没有为该选项定义任何操作(计算该部分可能是一个很好的过程,您可以自己学习和弄清楚)

property appearanceMode : {"Light", "Dark"}
property accentColors : {"Blue", "Purple", "Pink", "Red", "Orange", "Yellow", "Green", "Graphite"}
property highlightColors : {"Blue", "Purple", "Pink", "Red", "Orange", "Yellow", "Green", "Graphite", "Other"}

set chosenAppearanceMode to (choose from list appearanceMode ¬
    with title "Please Choose Your Accent Color" with prompt ¬
    "Please Choose Your Accent Color" OK button name ¬
    "OK" cancel button name "CANCEL") as string

set chosenAccentColor to (choose from list accentColors ¬
    with title ¬
    "Please Choose Your Accent Color" with prompt ¬
    "Please Choose Your Accent Color" OK button name ¬
    "OK" cancel button name "CANCEL") as string

set chosenHighlightColor to (choose from list highlightColors ¬
    with title ¬
    "Please Choose Your Highlight Color" with prompt ¬
    "Please Choose Your Highlight Color" OK button name ¬
    "OK" cancel button name "CANCEL") as string

tell application "System Preferences"
    reveal anchor "Main" of pane id "com.apple.preference.general"
end tell

tell application "System Events"
    repeat until exists of checkbox chosenAppearanceMode of window "General" of application process "System Preferences"
        delay 0.1
    end repeat
    -- Appearance
    click checkbox chosenAppearanceMode of window "General" of application process "System Preferences"
    -- Accent Color
    click checkbox chosenAccentColor of window "General" of application process "System Preferences"
    -- Dropdown Menu For Highlight Color
    click pop up button 1 of window "General" of application process "System Preferences"
    -- Highlight Color
    click menu item chosenHighlightColor of menu 1 of pop up button 1 of window "General" of application process "System Preferences"
end tell

tell application "System Preferences" to quit