Skip to content

Instantly share code, notes, and snippets.

@chris1111
Created April 7, 2024 13:17
Show Gist options
  • Save chris1111/1220fcc6a79d2b1e11037ab354043014 to your computer and use it in GitHub Desktop.
Save chris1111/1220fcc6a79d2b1e11037ab354043014 to your computer and use it in GitHub Desktop.
AppleScript using the Terminal (do script) to create the disk
# By chris1111
#
# Copyright (c) 2024 chris1111. All Right Reserved.
# Credit: Apple
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Version "1.0" by chris1111
# Vars
set theAction to button returned of (display dialog "
Welcome Create Install Media
You can create a bootable USB key
from macOS High Sierra 10.13 to macOS Sonoma 14
Format your USB Drive with Disk Utility
in the format Mac OS Extended (Journaled)
GUID Partition Map
*****************************
You must quit Disk Utility to continue
installation !" with icon note buttons {"Quit", "Create Install Media"} cancel button "Quit" default button {"Create Install Media"})
--If Create Install Media
if theAction = "Create Install Media" then
do shell script "open -F -a 'Disk Utility'"
delay 1
tell application "Disk Utility"
activate
end tell
repeat
if application "Disk Utility" is not running then exit repeat
end repeat
activate me
set Volumepath to paragraphs of (do shell script "ls /Volumes")
set Diskpath to choose from list Volumepath with prompt "
To continue, select the volume you want to use, then press the OK button" OK button name "OK" with multiple selections allowed
if Diskpath is false then
display dialog "Quit Installer " with icon 0 buttons {"EXIT"} default button {"EXIT"}
return
return (POSIX path of Diskpath)
end if
try
--If Continue
set theAction to button returned of (display dialog "
Choose the location of your Install macOS.app" with icon note buttons {"Quit", "10.13 to Sonoma 14"} cancel button "Quit" default button {"10.13 to Sonoma 14"})
if theAction = "10.13 to Sonoma 14" then
--If 10.13 to Sonoma 14
set InstallOSX to choose file of type {"XLSX", "APPL"} default location (path to applications folder) with prompt "Choose your Install macOS.app"
set OSXInstaller to POSIX path of InstallOSX
delay 2
set the_results to (display dialog "Please confirm your choice?
Create Install Media from --> " & (InstallOSX as text) & "
Install to --> " & (Diskpath as text) with icon note buttons {"Cancel", "OK"} cancel button "Cancel" default button "OK")
set button_returned to button returned of the_results
if button_returned is "OK" then tell application "Terminal"
activate
set currentTab to do script "sudo \"" & OSXInstaller & "Contents/Resources/createinstallmedia\" --volume /Volumes/\"" & Diskpath & "\" --nointeraction"
end tell
end if
end try
end if
@chris1111
Copy link
Author

In this AppleScript I use the Terminal (do script) to create the disk

Screenshot

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