Skip to content

Instantly share code, notes, and snippets.

@stek29
Last active June 14, 2022 17:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stek29/dd27759e5c96de21a33009ac914b9f4e to your computer and use it in GitHub Desktop.
Save stek29/dd27759e5c96de21a33009ac914b9f4e to your computer and use it in GitHub Desktop.
do shell script "diskutil mount disk0s3"
tell application "System Events"
tell application "System Preferences"
set current pane to pane id "com.apple.preference.startupdisk"
activate
delay 1
end tell
tell application process "System Preferences"
delay 0.3
tell window "Startup Disk"
set lockFound to false
repeat with x from 1 to number of buttons
if lockFound is false then
if title of button x is "Click the lock to make changes." then
click button x
set lockFound to true
repeat while title of button x is "Authenticating..."
delay 1
end repeat
else if title of button x is "Click the lock to prevent further changes." then
set lockFound to true
end if
else
exit repeat
end if
end repeat
set targetPrefix to "Windows"
set targetIndex to 0
set options to group of UI element 1 of scroll area 1
repeat with i from 1 to number of options
set x to item i of options
if name of UI element 3 of x starts with targetPrefix then
set targetIndex to i
exit repeat
end if
end repeat
if targetIndex is 0 then
error "cant find " & targetPrefix & " in list of options"
end if
key code 48
delay 0.1
repeat with i from 1 to number of options
key code 123
delay 0.1
end repeat
repeat with i from 2 to targetIndex
key code 124
delay 0.1
end repeat
click button "Restart…"
delay 0.3
click button "Restart" of sheet 1
return true
end tell
end tell
end tell
@stek29
Copy link
Author

stek29 commented Jun 14, 2022

needs "Use keyboard navigation to move focus between controls" to be enabled, see https://apple.stackexchange.com/a/422191/152562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment