Skip to content

Instantly share code, notes, and snippets.

@stek29
Last active June 14, 2022 17:40
Show Gist options
  • Save stek29/dd27759e5c96de21a33009ac914b9f4e to your computer and use it in GitHub Desktop.
Save stek29/dd27759e5c96de21a33009ac914b9f4e to your computer and use it in GitHub Desktop.

Revisions

  1. stek29 revised this gist Jun 14, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions StartupDisk.applescript
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ 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"
  2. stek29 revised this gist Nov 4, 2021. 1 changed file with 59 additions and 62 deletions.
    121 changes: 59 additions & 62 deletions StartupDisk.applescript
    Original file line number Diff line number Diff line change
    @@ -1,68 +1,65 @@
    do shell script "diskutil mount disk0s3"

    tell application "System Events"
    try
    tell application "System Preferences"
    set current pane to pane id "com.apple.preference.startupdisk"
    activate
    end tell
    tell application "System Preferences"
    set current pane to pane id "com.apple.preference.startupdisk"
    activate
    end tell

    tell application process "System Preferences"
    delay 0.3

    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
    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
    end repeat

    if targetIndex is 0 then
    error "cant find " & targetPrefix & " in list of options"
    else
    exit repeat
    end if

    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
    on error
    delay 0.5
    tell application "System Preferences"
    if current pane is pane id "com.apple.preference.startupdisk" then quit
    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
    return false
    end try
    end tell
    end tell
  3. stek29 renamed this gist Nov 2, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. stek29 created this gist Nov 2, 2021.
    68 changes: 68 additions & 0 deletions StartupDisk.automation
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    tell application "System Events"
    try
    tell application "System Preferences"
    set current pane to pane id "com.apple.preference.startupdisk"
    activate
    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

    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
    on error
    delay 0.5
    tell application "System Preferences"
    if current pane is pane id "com.apple.preference.startupdisk" then quit
    end tell
    return false
    end try
    end tell