Skip to content

Instantly share code, notes, and snippets.

@mmertsock
Created December 24, 2019 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmertsock/db09ca302cc38d805d86a06aecb3335a to your computer and use it in GitHub Desktop.
Save mmertsock/db09ca302cc38d805d86a06aecb3335a to your computer and use it in GitHub Desktop.
AppleScript to pick a random macOS accent color
-- https://apple.stackexchange.com/a/338355/13458
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 "Dark" of window "General" of application process "System Preferences"
delay 0.1
end repeat
set accentColors to {"Blue", "Purple", "Pink", "Red", "Orange", "Yellow", "Green", "Graphite"}
repeat with a from 1 to 5
set randIndex to random number from 1 to count of accentColors
set theColor to item randIndex of accentColors
set isColorSelected to value of checkbox theColor of window "General" of application process "System Preferences"
if isColorSelected is 0 then
click checkbox theColor of window "General" of application process "System Preferences"
exit repeat
end if
end repeat
end tell
tell application "System Preferences" to quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment