macOS – Problems Creating OS X Installer with AppleScript

applescriptinstallmacos

I’m trying to create a bootable OS X Installer (Including Mavericks, Yosemite and El Capitan) on an external disk with AppleScript. But now I have some trouble. Here is the code:

display dialog "Which version of OS X Installation would you like to create?" with icon caution buttons {"OS X Mavericks", "OS X Yosemite", "OS X El Capitan"}
if the button returned of the result is " OS X El Capitan" then
    tell application "Terminal"
        activate
        do shell script "sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app --nointeraction"
    end tell
end if

My working direction is:

  1. Choose which version you would like to create.

  2. Activate Terminal and ask Terminal to execute the code (It works well within Terminal):

    sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app --nointeraction
    

There is an error (picture below) when I try to run the script. It seems there is something wrong with the path, and it seems AppleScript cannot recognize a path with space like this: Install\ OS\ X\ EL\ Capitan.app.

I tried the following script (this one works well)

set pathwithSpaces to "/Users/John/Desktop/This is a test.docx"
do shell script "rm -r " & quoted form of pathwithSpaces

But my updated one still doesn’t work.

Could you give me some hints? Or am I in a wrong direction?

enter image description here

Best Answer

Just a hint how to start but to long to add it as comment:

Start with this:

set the_results to (display dialog "Which version of OS X Installation would you like to create?" with icon caution buttons {"OS X Mavericks", "OS X Yosemite", "OS X El Capitan"})
set button_returned to button returned of the_results
if button_returned is "OS X El Capitan" then tell application "Terminal"
    activate
    set currentTab to do script ("sudo /Applications/Install\\ OS\\ X\\ El\\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\\ OS\\ X\\ El\\ Capitan.app --nointeraction;")
end tell
if button_returned is "OS X Yosemite" then tell application "Terminal"
    activate
    ...

You still have to handle the sudo password.