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

时间:2018-10-07 21:57:15

标签: cocoa applescript macos-mojave

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

我的第一次尝试是使用AppleScript。但是我意识到API尚未更新:

enter image description here

带下划线的API可以使用,但只有2种颜色可供选择,而新的操作系统则有8种。

我想知道是否有任何解决方法。语言不受限制,只要它可以工作即可。谢谢。

1 个答案:

答案 0 :(得分:1)

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

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