-- case sensitive
global big_sur -- and later
global my_password
global media_name
set my_password to "test"
try
set boot_rom_version to last word of (do shell script "system_profiler SPHardwareDataType | grep -i \"Boot Rom Version\"")
if (length of boot_rom_version is 7) and (character 1 of boot_rom_version is "1") then -- older Systems like Mavericks truncates the sn
set boot_rom_version to boot_rom_version & ".0"
end if
set big_sur to false
on error --Big Sur
set boot_rom_version to last word of (do shell script "system_profiler SPHardwareDataType | grep -i \"System Firmware Version\"")
set big_sur to true
end try
try -- unmount all ESPs found
set all_esp to do shell script "ls /Volumes | grep EFI"
repeat with the_esp in every paragraph of all_esp
try
do shell script "diskutil unmount /Volumes/" & quoted form of the_esp
end try
end repeat
end try
try
set EFI_List to do shell script "diskutil list | grep 'EFI EFI'"
on error --Monterey
set EFI_List to do shell script "diskutil list | grep 'EFI'"
end try
-- is it blessed by /dev/disk?s1 ?
try
set current_blessing to do shell script ("bless --getboot")
if current_blessing ends with "s1" then
do_shell_script_sudo("diskutil mount " & current_blessing)
tag_esp(current_blessing) -- √
tell application "Finder"
activate
try
open disk "EFI"
display dialog "blessed bootloader found at" & return & current_blessing
on error
display dialog "no bootloader found"
end try
end tell
return -- end the script, we're done
end if
on error
set current_blessing to ""
try
set uuid_bless to do shell script ("Bless --getboot --verbose")
on error uuid_bless -- verbose gives uuid of ESP
--display dialog "error uuid_bless" & return & uuid_bless
end try
end try
repeat with the_disk in every paragraph of EFI_List
set disk_x_s_1 to (last word of (the_disk as string))
try
set uuid to ""
set uuid_raw to (do shell script ("diskutil info " & disk_x_s_1 & " | grep 'Partition UUID'"))
set uuid to ((word -5 of uuid_raw) & "-" & (word -4 of uuid_raw) & "-" & (word -3 of uuid_raw) & "-" & (word -2 of uuid_raw) & "-" & (word -1 of uuid_raw)) as text
if uuid is in uuid_bless then -- it's wtf but uuid_bless needs my
set current_blessing to "/dev/" & disk_x_s_1
set esp_from_uuid to true
do_shell_script_sudo("diskutil mount " & current_blessing)
tag_esp(current_blessing)
display dialog "blessed bootloader found at:" & return & current_blessing & return & return & "blessed by uuid:" & return & uuid
tell application "Finder"
activate
try
open disk "EFI"
on error
display dialog "no bootloader found by uuid method"
end try
end tell
return -- end the script, we're done, found via disk uuid
end if
end try
end repeat
-- no blessed bootloader found, scan thru all ESPs I can find and check for OC, Refind(plus) or OCLP bootloaders
repeat with x in every paragraph of EFI_List
set diskxsy to last word of x
delay 1
do_shell_script_sudo("diskutil mount " & diskxsy)
repeat
delay 0.1
if folder_exists("/Volumes/EFI") then exit repeat -- wait for mounted EFI Volume
end repeat
tag_esp(diskxsy)
set oc_diskxsy to ""
if file_exists("/Volumes/EFI/EFI/BOOT/BOOTx64.efi") or file_exists("/Volumes/EFI/System/Library/CoreServices/boot.efi") then
set oc_diskxsy to diskxsy
exit repeat
else
do_shell_script_sudo("diskutil unmount " & diskxsy)
end if
end repeat
if oc_diskxsy is not "" then display dialog media_name & return & "has a Bootloader located at " & oc_diskxsy buttons {"OK"} giving up after 10
tell application "Finder"
activate
try
open disk "EFI"
on error
display dialog "no bootloader found"
end try
end tell
on file_exists(thEFIle) -- (String) as Boolean
tell application "System Events"
if exists file thEFIle then
return true
else
return false
end if
end tell
end file_exists
on folder_exists(theFolder) -- (String) as Boolean
tell application "System Events"
if exists folder theFolder then
return true
else
return false
end if
end tell
end folder_exists
on do_shell_script_sudo(the_text)
if my_password is not "" then
if big_sur then
try -- if the password is wrong it runs into an error
return do shell script "echo " & my_password & " | sudo -S " & the_text
on error number errorNumber
display dialog "do_shell_script_sudo: Error: " & (errorNumber as text) & return & the_text
return do shell script the_text with administrator privileges
-- and ask for the correct password
end try
else -- not big sur
return do shell script the_text password my_password with administrator privileges
end if
else -- no password given
return do shell script the_text with administrator privileges
end if
end do_shell_script_sudo
on tag_esp(the_partition)
set the_current_disk to (characters 1 thru -3 of the_partition) as string
set media_name to do shell script "diskutil info " & the_current_disk & " | grep 'Media Name'"
set AppleScript's text item delimiters to ":"
set media_name to the last text item of media_name
set AppleScript's text item delimiters to ""
try
do_shell_script_sudo("touch /Volumes/EFI/" & (quoted form of media_name)) -- make a tag
return 1
end try
return 0
end tag_esp