gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:40:12 26 4
gpt4 key购买 nike

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

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

enter image description here

带下划线的 API 可以工作,但它只有 2 种颜色选项,而新操作系统有 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

关于cocoa - 以编程方式更改 macOS Mojave 强调色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52693268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com