Reputation: 601
I'm writing an app that allows user to set the accent color of the macOS Mojave.
My first attempt was using AppleScript. But I realized that the API is not up to date yet:
The underlined API works, but it only has 2 color options, while the new OS has 8.
I'm wondering if there is any workaround. Language is not limited, as long as it works. Thanks.
Upvotes: 2
Views: 1544
Reputation: 3142
Here is a complete AppleScript solution which allows the user to choose light or dark mode, highlight colors, and accent colors. If the user chooses “Other” in the highlight color options, the script may throw an error because I did not define any actions for that option (figuring that part may be a good process for you to learn and figure out on your own)
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
Upvotes: 1