Last active
June 14, 2022 17:40
-
-
Save stek29/dd27759e5c96de21a33009ac914b9f4e to your computer and use it in GitHub Desktop.
automate startup disk selection with SIP enabled - see https://apple.stackexchange.com/questions/398711/how-can-i-script-the-bootup-disk-in-macos-catalina-without-disabling-sip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
needs "Use keyboard navigation to move focus between controls" to be enabled, see https://apple.stackexchange.com/a/422191/152562