Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global MyOSXFileExtension
- global OSX_App
- global OSX_DMG
- global OSXisFound
- -- Version of DiskMaker X
- set CurrentLDMVersion to "304"
- set DebugMode to false
- set LDMIcon to path to resource "LDM_Icon.icns" in bundle (path to me)
- set CurrentOS to do shell script "sw_vers -productVersion | cut -c 1-4"
- (*************************************************
- *** Strings declarations to allow localization ********
- *************************************************)
- -- Update dialog
- set DialogUpdate1Loc to localized string of "A newer version of DiskMaker X is available. Do you want to download it?"
- set NotNowThanksLoc to localized string of "Not now, thanks"
- set GetNewVersionLoc to localized string of "Get new version"
- -- New Version of OS X available dialog
- set NewOSXVersionAvailableLoc1 to localized string of "A newer version of OS X is available. Do you want to download it? It's better to have the most up-to-date version of OS X to build your install disk."
- set LatestVersionLoc to localized string of "The latest version is:"
- set YourVersionLoc to localized string of "Your OS X Version is:"
- set NewOSXVersionDownload to localized string of "Download now from App Store"
- set NewOSXVersionNotYet to localized string of "Not now"
- set AppStoreLaunchedLoc to localized string of "The App Store is now displaying the latest version of OS X. Please download it, then launch DiskMaker X again when it's over."
- -- Welcome Dialog
- set WelcomeLoc to localized string of "Welcome to DiskMaker X!"
- set MyWhichOSXVersion to localized string of "Which version of OS X do you wish to make a boot disk of?"
- -- Copy found dialog
- set AcopyofOSXwasfoundinfolderLoc to localized string of "I found a copy of the installer software in this folder:"
- set DoyouwishtousethiscopyLoc to localized string of "Do you wish to use this copy?"
- set MyUseAnotherCopy to localized string of "Use another copy…"
- set MyUseThisCopyLoc to localized string of "Use this copy"
- -- Some standard buttons
- set QuitButtonLoc to localized string of "Quit"
- set CancelButtonLoc to localized string of "Cancel"
- set ContinueButtonLoc to localized string of "Continue"
- -- No installer found dialog
- set LDMDiskDetectedLoc1 to localized string of "I detected that the following disk was already built with DiskMaker X:"
- set LDMDiskDetectedLoc2 to localized string of "Do you want to use it to build your new install disk ?"
- set MyCouldNotFoundInstallOSXAppLoc to localized string of "No Installer application could be found. Click on Select a file and choose the OS X Installer application OR the InstallESD.dmg file. If you can't find a Lion or Mountain Lion Install application, please check the FAQ."
- set ChooseOSXFileLoc to localized string of "Select an Install file…"
- set ChooseOSXFilePrompt1Loc to localized string of "Select "
- set ChooseOSXFilePrompt2Loc to localized string of " OR the InstallESD.dmg file only :"
- set MyCheckTheFaq to localized string of "Check the FAQ"
- set MyCreateTheUSBDrive to localized string of "To create a boot disk, please connect a USB, FireWire disk or insert an SD-Card (8 GB minimum). Then click on Choose the disk."
- set MyLionBootDiskIsReadyLoc to localized string of "Your OS X boot disk is ready! To use it, reboot your Mac and press the Option (Alt) key, or select it in the Startup Disk preference."
- set MyMakeADonationLoc to localized string of "Make a donation"
- set MyWebSite to localized string of "http://liondiskmaker.com/"
- set WannaMakeADonation to localized string of "If you enjoyed using DiskMaker X, your donations are also much appreciated."
- set StartupPrefLoc to localized string of "Open Startup Disk Preference"
- -- Error dialog
- set MyDiskCouldNotBeCreatedError to localized string of "The disk could not be created because of an error: "
- set MyAnErrorOccured to localized string of "An error occured: "
- set MyUseThisDisk to localized string of "Use this disk"
- set MyEraseAndCreateTheDisk to localized string of "Erase then create the disk"
- -- Kind of physical disk dialog
- set WhichKindOfDiskYouUseLoc to localized string of "Which kind of disk will you use?"
- set WhichKindOfDiskExplainationLoc to localized string of "If you have an 8 GB USB thumb drive, it will be completely erased. If you choose another kind of disk, ONLY the chosen volume will be erased. Your other disks and volumes will be left untouched."
- set WhichKindOfDiskIsUSB8GBLoc to localized string of "An 8 GB USB thumb drive"
- set WhichKindOfDiskIsAnyOtherDiskLoc to localized string of "Another kind of disk"
- -- Last alert dialog
- set LastAlertMessageLocVolume to localized string of "WARNING ! THE WHOLE CONTENTS OF THIS VOLUME WILL BE ERASED!"
- set LastAlertMessageLocDisc to localized string of "WARNING: THE WHOLE CONTENT OF THE DISK (AND EVERY OTHER VOLUME OF THIS DISK) WILL BE ERASED!"
- set LastAlertPart1Loc to localized string of "You are about to erase the volume : "
- set LastAlertPart2Loc to localized string of "If you continue, all the data on it will be lost. Are you sure you want to do this ?"
- set LastAlertPart3Loc to localized string of "The following volumes are on the same disk and will be erased:"
- -- Alert for Mavericks
- set MavericksAdminAlertLoc to localized string of "You will be required to type your login and password soon."
- set MavericksAdminAlertTitleLoc to localized string of "The next step will ask for administrator privileges to build the install disk, so please type your administrator login and password when necessary."
- -- Can't use this disk dialog
- set MyNotTheCorrectOSXFileLoc to localized string of "This file can't be used to create a Lion Installation disk."
- -- Disk selection dialog
- set HereAreTheDisksLoc to localized string of "Here are the disks you may want to use to create your boot disk"
- set ChooseDiskToErase to localized string of "Please choose the disk you wish to erase"
- set ChooseThisDiskLoc to localized string of "Choose this disk"
- -- Miscellanous localizations
- set MyCantUseThisDisk to localized string of "This disk can't be used because it is not a removable disk."
- set ChooseDiskToEraseLoc to localized string of "Please choose the disk you wish to erase"
- -- No disk available alert
- set NoDiskAvailableLoc to localized string of "Sorry, I can't find a disk to use… Please plug a disk, then relaunch DiskMaker X."
- -- Icon Error Management
- set IconError1Loc to localized string of "Sorry, I could not get the icon to personnalize the disk. Don't worry, your OS X disk will work fine."
- set IconError2Loc to localized string of "I will leave a copy of the compressed icon named "
- set IconError3Loc to localized string of ".zip on your Desktop so that you can still personnalize the disk yourself."
- set IconError4Loc to localized string of "Check the FAQ on the web site for more info."
- -- ASObjcC strings for activity bar
- set ASObjCMessageLoc to localized string of "Please wait, DiskMaker X is copying files…"
- set ASObjCMessageDetailLoc to localized string of "This may take a while… Be patient !"
- set ASObjCMessageDetailCurrentLoc to localized string of "Copying file: "
- set AlreadyALDMDiskLoc to localized string of "The following volume has already been used as a bootable install disk. Do you want DiskMaker X to update it ?"
- set AlreadyALDMDiskConfirmLoc to localized string of "Update this volume"
- set AlreadyALDMDiskCancelLoc to localized string of "User another volume"
- set CopyingFilesLoc to localized string of "Copying files…"
- set MyPaypalLoc to localized string of "http://liondiskmaker.com/?page_id=149"
- set MyNotOSX106CompatibleLoc to localized string of "Sorry, DiskMaker X is currently not able yet to build a Mavericks Install disk from Mac OS X 10.6. Backup the OS X Mavericks Installer application, upgrade to Mavericks, then build your install disk with DiskMaker X."
- set MoreInfoButtonLoc to localized string of "More information"
- set DMGIncompleteLoc to localized string of "Sorry, your OS X Install app or DMG may be incomplete. Delete your install application, then download it again from the App Store."
- set OpenAppStoreLoc to localized string of "Open App Store"
- -- Path to sound resource
- set SoundPath to ((path to resource "woohoo.mp3"))
- -- Check if a new version is available. Should have been done sooner.
- try
- with timeout of 10 seconds
- set LatestLDMVersion to do shell script "curl http://liondiskmaker.com/CurrentLDMVersion" as string
- if LatestLDMVersion is greater than CurrentLDMVersion then
- display dialog DialogUpdate1Loc buttons {QuitButtonLoc, NotNowThanksLoc, GetNewVersionLoc} default button 3
- set ResultButton to the button returned of the result
- if ResultButton is GetNewVersionLoc then
- open location MyWebSite
- return
- else
- if ResultButton is QuitButtonLoc then
- return
- end if
- end if
- end if
- end timeout
- end try
- ## 03/08/12 : added this line to prevent some ASObC Runner issues
- try
- tell me to do shell script "killall -9 'ASObjC Runner'"
- end try
- -- We copy the pref file for ASobjCRunner in Prefs folder. Makes things easier for later.
- -- I tried to use the ASObjCRunner-N tip to avoid displaying the alerts, but DiskMaker X does not
- -- work properly then :-/
- -- If you have better ways to do it, I welcome suggestions :)
- set Prefpath to (path to preferences folder)
- set PosixPrefPath to (quoted form of POSIX path of Prefpath)
- set SourcePrefPath to (quoted form of POSIX path of (path to resource "au.com.myriad-com.ASObjC-Runner.plist"))
- delay 1
- try
- tell me to do shell script "cp -R " & SourcePrefPath & " " & PosixPrefPath
- end try
- -- Then we can call ASObjCRunner.app which is enclosed in the bundle
- set runnerPath to (path to resource "ASObjC Runner.app")
- ## 03/08/12 : modified "& to " & - Seems to improve error with ASObjC Runner
- tell me to do shell script "open " & (quoted form of POSIX path of runnerPath) & " &> /dev/null &"
- activate
- -- First, we ask which OS we want to deal with so that we can declare a few variables.
- display dialog (WelcomeLoc & return & return & MyWhichOSXVersion) buttons {"Lion (10.7)", "Mountain Lion (10.8)", "Mavericks (10.9)"} default button 3 with icon path to resource "LDM_Icon.icns" in bundle (path to me)
- set the button_pressed to the button returned of the result
- if the button_pressed is "Mavericks (10.9)" then
- if CurrentOS is "10.6" then
- display dialog MyNotOSX106CompatibleLoc buttons {QuitButtonLoc, MoreInfoButtonLoc} default button 2 with icon path to resource IconName in bundle (path to me)
- set the button_pressed to the button returned of the result
- if button_pressed is MoreInfoButtonLoc then
- open location "http://liondiskmaker.com/?page_id=28"
- else
- return
- end if
- return
- end if
- -- Variables for OS X 10.9 (aka "Mavericks")
- set OSXVersion to "10.9"
- set OSFileName to "Install OS X Mavericks"
- set IconName to "Maverick.icns"
- set DiskIconName to "MaverickDiskIcon512"
- set FinalDiskName to "OS X 10.9 Mavericks Install Disk"
- set InstallDiskNameLoc to localized string of "OS X 10.9 Install Disk"
- set OSXInstallESDName to "OS X Install ESD"
- set BaseSystemName to "OS X Base System"
- set OSXBackground to "MavericksBackground.png"
- else
- if the button_pressed is "Mountain Lion (10.8)" then
- -- Variables for Mountain Lion
- set OSXVersion to "10.8"
- set OSFileName to "Install OS X Mountain Lion"
- set IconName to "MountainLion.icns"
- set DiskIconName to "MLDiskIcon512"
- set FinalDiskName to "OS X Mountain Lion Install Disk"
- set InstallDiskNameLoc to localized string of "OS X Mountain Lion Install Disk"
- set OSXInstallESDName to "Mac OS X Install ESD"
- set BaseSystemName to "Mac OS X Base System"
- set OSXBackground to "MountainLion_Background.png"
- else
- -- Variables for Lion
- set OSXVersion to "10.7"
- set OSFileName to "Install Mac OS X Lion"
- set IconName to "Lion.icns"
- set DiskIconName to "LionDiskIcon512"
- set FinalDiskName to "Mac OS X Lion Install Disk"
- set InstallDiskNameLoc to localized string of "OS X Lion Install Disk"
- set OSXInstallESDName to "Mac OS X Install ESD"
- set BaseSystemName to "Mac OS X Base System"
- set OSXBackground to "MountainLion_Background.png"
- end if
- end if
- -- First I check if I can find the install app in the Applications folder.
- -- I will use Spotlight only if it does not exist here.
- set OSXisFound to "Not found yet"
- tell application "System Events"
- if exists file ("/Applications/" & OSFileName & ".app/Contents/SharedSupport/InstallESD.dmg") then
- set OSX_DMG to "'/Applications/" & OSFileName & ".app/Contents/SharedSupport/InstallESD.dmg'"
- if OSXVersion is "10.9" then
- set OSX_App to quoted form of "/Applications/Install OS X Mavericks.app"
- end if
- set OSXisFound to "Found"
- display dialog (AcopyofOSXwasfoundinfolderLoc & return & return & "/Applications" & return & return & DoyouwishtousethiscopyLoc) buttons {CancelButtonLoc, MyUseAnotherCopy, MyUseThisCopyLoc} default button 3 with icon path to resource IconName in bundle (path to me)
- set the button_pressed to the button returned of the result
- -- If it's not the right app, you may want to choose another app.
- if the button_pressed is MyUseThisCopyLoc then
- set OSX_DMG to quoted form of ("/Applications/" & OSFileName & ".app/Contents/SharedSupport/InstallESD.dmg")
- set OSXisFound to "Found"
- set OSX_App to quoted form of ("/Applications/" & OSFileName & ".app")
- else
- if the button_pressed is MyUseAnotherCopy then
- my theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
- end if
- if the button_pressed is CancelButtonLoc then
- return
- end if
- end if
- end if
- end tell
- -- If we can't find in /Applications, then we use Spotlight
- if OSXisFound is "Not found yet" then
- set OSSearch to (do shell script "mdfind -name '" & OSFileName & "' | grep -v Library | head -1")
- set OSSearchResultNumber to (do shell script "echo " & OSSearch & " | wc -l ") as integer
- if OSSearch is not "" then
- set OSXFolder to OSSearch
- display dialog (AcopyofOSXwasfoundinfolderLoc & return & return & OSXFolder & return & return & DoyouwishtousethiscopyLoc) buttons {CancelButtonLoc, MyUseAnotherCopy, MyUseThisCopyLoc} default button 3 with icon path to resource IconName in bundle (path to me)
- set the button_pressed to the button returned of the result
- if the button_pressed is MyUseThisCopyLoc then
- if OSXVersion is "10.9" then
- set OSX_App to quoted form of (POSIX path of OSXFolder)
- set OSX_DMG to quoted form of ((POSIX path of OSXFolder) & "/Contents/SharedSupport/InstallESD.dmg")
- else
- set OSX_DMG to quoted form of ((POSIX path of OSXFolder) & "/Contents/SharedSupport/InstallESD.dmg")
- end if
- else
- if the button_pressed is MyUseAnotherCopy then
- my theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
- end if
- if the button_pressed is CancelButtonLoc then
- return
- end if
- end if
- else
- display dialog MyCouldNotFoundInstallOSXAppLoc buttons {CancelButtonLoc, MyCheckTheFaq, ChooseOSXFileLoc} default button 3 with icon caution
- set the button_pressed to the button returned of the result
- if the button_pressed is MyCheckTheFaq then
- open location MyWebSite
- return
- else
- if the button_pressed is ChooseOSXFileLoc then
- my theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
- end if
- end if
- end if
- end if
- (********************* Creating a bootable disc ***************************)
- -- New routine checks if a file exists with a .LionDiskMaker_OSVersion hidden file at root.
- tell application "Finder"
- set DontEraseTheDisk to false
- set LDMAlreadyThere to false
- set TheNumberOfEjectableDisks to the number of (every disk whose (ejectable is true))
- try
- set TheEjectableDiskList to the name of (every disk whose (ejectable is true))
- on error
- display dialog "No removable disk found !"
- return
- end try
- set n to 1
- repeat with loopVar from n to TheNumberOfEjectableDisks
- set MyDisk to (item n of TheEjectableDiskList)
- set HiddenFileToFind to "/Volumes/" & MyDisk & "/.LionDiskMaker_OSVersion" as string
- if exists HiddenFileToFind as POSIX file then
- set LDMAlreadyThere to true
- set NewVolumeName to MyDisk
- set AlreadyLDMDisk to MyDisk
- set MyErasefullDisc to false
- end if
- set n to n + 1
- end repeat
- end tell
- if LDMAlreadyThere is true then
- activate
- display dialog LDMDiskDetectedLoc1 & return & return & AlreadyLDMDisk & return & return & LDMDiskDetectedLoc2 & return buttons {AlreadyALDMDiskCancelLoc, AlreadyALDMDiskConfirmLoc} default button 2 with icon path to resource IconName in bundle (path to me)
- set the button_pressed to the button returned of the result
- if the button_pressed is AlreadyALDMDiskConfirmLoc then
- set MyTargetDisk to AlreadyLDMDisk
- set MyTargetDiskPath to the quoted form of (POSIX path of MyTargetDisk)
- else
- set LDMAlreadyThere to false
- end if
- end if
- if LDMAlreadyThere is false then
- -- We have to know if the selected disk is a 8 GB thumbnail disk or something else to choose the proper way to erase the disk.
- activate
- display alert WhichKindOfDiskYouUseLoc message WhichKindOfDiskExplainationLoc & return & return buttons {CancelButtonLoc, WhichKindOfDiskIsAnyOtherDiskLoc, WhichKindOfDiskIsUSB8GBLoc} default button 3 as critical
- set the button_pressed to the button returned of the result
- if the button_pressed is WhichKindOfDiskIsUSB8GBLoc then
- set MyErasefullDisc to true
- else
- if the button_pressed is WhichKindOfDiskIsAnyOtherDiskLoc then
- set MyErasefullDisc to false
- else
- return
- end if
- end if
- -- We have to define the list of disks available for use.
- tell application "Finder"
- if MyErasefullDisc is true then
- try
- set ListOfDisks to the name of (every disk whose (ejectable is true) and (capacity is less than 8.5E+10))
- on error
- display dialog NoDiskAvailableLoc buttons {QuitButtonLoc} default button 1 with icon path to resource IconName in bundle (path to me)
- return
- end try
- set LastAlertMessageLoc to LastAlertMessageLocDisc
- else
- try
- set ListOfDisks to the name of (every disk whose (ejectable is true))
- on error
- display dialog NoDiskAvailableLoc buttons {QuitButtonLoc} default button 1 with icon path to resource IconName in bundle (path to me)
- return
- end try
- set LastAlertMessageLoc to LastAlertMessageLocVolume
- end if
- end tell
- set MyTargetDisk to choose from list ListOfDisks with prompt HereAreTheDisksLoc with title ChooseDiskToEraseLoc cancel button name CancelButtonLoc OK button name ChooseThisDiskLoc default items 1 without multiple selections allowed and empty selection allowed
- if MyTargetDisk is not false then
- set MyTargetDiskPath to the quoted form of (POSIX path of MyTargetDisk)
- else
- display dialog NoDiskAvailableLoc buttons {QuitButtonLoc} default button 1 with icon path to resource IconName in bundle (path to me)
- return
- end if
- -- We get all the volumes which are part of the same disk as our target volume. Just to let the user know…
- set FullDiskName to do shell script "diskutil info " & quoted form of (MyTargetDisk as string) & " | grep 'Part Of Whole' | awk '{ print $4 }'"
- -- And we get the full size of the disk. Necessary a bit later.
- -- thanks @lolopb who managed to find a way to workaround a bad limitation with diskutil in 10.6…
- if MyErasefullDisc is true then
- try
- set FullListOfDisks to do shell script "for (( i = 2; i <= $(diskutil list " & FullDiskName & " | tail -n 1 | cut -c 75-76); i++)); do diskutil info " & FullDiskName & "s$i | grep \"Volume Name: \" | cut -c 30-75; done | grep -v 'Recovery HD'"
- on error errMsg number errNum
- set FullListOfDisks to ""
- set LastAlertPart2Loc to ""
- set LastAlertPart3Loc to ""
- end try
- else
- set FullListOfDisks to ""
- set LastAlertPart3Loc to ""
- end if
- -- Last Warning !!! There's no turning back from here.
- display alert LastAlertMessageLoc message LastAlertPart1Loc & return & return & MyTargetDisk & return & return & LastAlertPart2Loc & return & LastAlertPart3Loc & return & return & FullListOfDisks buttons {CancelButtonLoc, MyEraseAndCreateTheDisk} default button 2 as warning
- set the button_pressed to the button returned of the result
- if the button_pressed is CancelButtonLoc then
- return
- end if
- end if
- if OSXVersion is "10.9" then
- display alert MavericksAdminAlertTitleLoc message MavericksAdminAlertLoc buttons {CancelButtonLoc, ContinueButtonLoc} default button 2 as warning
- end if
- -- Disk creations begins ! --
- -- We use uuidgen to warrant a unique name to the disk (avoiding to erase other drives in the process…)
- if DontEraseTheDisk is false then
- set NewVolumeName to (do shell script "uuidgen")
- -- To avoid errors, we check that the disk is really ejectable.
- set IsEjectable to do shell script "diskutil info " & MyTargetDiskPath & " | grep -i \"Ejectable\" | awk '{ print $2}' "
- if IsEjectable is "No" then
- display dialog MyCantUseThisDisk with icon stop
- else
- -- The disk is completely formated using GUID partition scheme if the volume size is less than 4 GB. If the volume size is more than 4 GB, only this volume is reformated with Journaled HFS+.
- if MyErasefullDisc is true then
- tell me to do shell script "diskutil partitionDisk $(diskutil info " & MyTargetDiskPath & " | grep -i \"Part Of Whole\" | awk '{ print $4}') 1 GPT jhfs+ " & NewVolumeName & " R"
- else
- tell me to do shell script "diskutil eraseVolume JHFS+ " & NewVolumeName & " " & MyTargetDiskPath
- end if
- end if
- end if
- -- sometimes the volume is not mounted yet while the copy begins. We need to delay a bit...
- delay 2
- with timeout of 9999 seconds
- -- First, we unmount any occurence of the Base System and the OS X Install ESD disk. Just in case.
- try
- tell me to do shell script "hdiutil detach '/Volumes/" & BaseSystemName & "'"
- delay 2
- end try
- try
- tell me to do shell script "hdiutil detach '/Volumes/" & OSXInstallESDName & "'"
- delay 2
- end try
- try
- -- We mount the InstallESD image as read only, without showing it in the Finder (thanks Lolopb ;-) )
- try
- tell me to do shell script "hdiutil attach " & OSX_DMG & " -noverify -nobrowse"
- on error
- display dialog DMGIncompleteLoc buttons {QuitButtonLoc, OpenAppStoreLoc} default button 2
- set the button_pressed to the button returned of the result
- if the button_pressed is OpenAppStoreLoc then
- tell application "App Store.app" to activate
- end if
- return
- end try
- -- Then we mount the hidden BaseSystem.DMG file to get the System Version and copy the Utilities folder later.
- try
- tell me to do shell script "hdiutil attach '/Volumes/" & OSXInstallESDName & "/BaseSystem.dmg' -noverify -nobrowse"
- on error
- display dialog DMGIncompleteLoc buttons {QuitButtonLoc, OpenAppStoreLoc} default button 2
- set the button_pressed to the button returned of the result
- if the button_pressed is OpenAppStoreLoc then
- tell application "App Store.app" to activate
- end if
- return
- end try
- -- We get the version number. We will use it to rename the USB disk properly later.
- set OSXImageVersion to (do shell script "defaults read '/Volumes/" & BaseSystemName & "/System/Library/CoreServices/SystemVersion' ProductVersion") as string
- tell application "Finder"
- open disk NewVolumeName
- -- Total Finder can prevent the modification of windows, so this piece of code will not run if it is running . Thanks to Dj Padzenzky for this part.
- try
- «event BATFchck»
- on error
- set bounds of Finder window 1 to {1, 44, 503, 493}
- set sidebar width of Finder window 1 to 0
- set statusbar visible of Finder window 1 to true
- set current view of Finder window 1 to icon view
- end try
- end tell
- (*********************************************************************************************************************************)
- -- There are great differences between Mavericks and previous versions of OS X.
- -- If we deal with Mavericks, we use now a built-in command provided by Apple. It requires admin authorization though.
- if OSXVersion is "10.9" then
- try
- tell me to do shell script "killall -9 'ASObjC Runner'"
- end try
- delay 1
- ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
- activate
- tell me to do shell script "sudo " & OSX_App & "/Contents/Resources/createinstallmedia --volume /Volumes/" & NewVolumeName & " --applicationpath " & OSX_App & " --nointeraction &> /tmp/createinstallmedia.log &" with administrator privileges
- try
- repeat with i from 1 to 999999
- set CreateInstallMediaStatus to (do shell script "ps auxc | grep createinstallmedia | wc -l | awk '{ print $1 }'")
- set CreateInstallMediaLog to (do shell script "tail -n 1 /tmp/createinstallmedia.log")
- set CheckIfDiskIsErased to (do shell script "tail -n 1 /tmp/createinstallmedia.log | grep '100%' | wc -l | cut -c 8")
- if CheckIfDiskIsErased is "1" then
- set CreateInstallMediaLog to CopyingFilesLoc
- end if
- tell application "ASObjC Runner.app"
- set properties of «class aÂs8» to {«class aÂp2»:CreateInstallMediaLog}
- if CreateInstallMediaLog is "Done." then
- if DebugMode is false then
- tell me to do shell script "rm /tmp/rsyncldm.log"
- end if
- exit repeat
- end if
- end tell
- end repeat
- tell application "ASObjC Runner.app" to «event cÂc0cÂC0»
- on error
- RemoveTheCrubs()
- end try
- --tell application "Finder"
- -- set name of disk "Install OS X Mavericks" to NewVolumeName
- --end tell
- else
- set MyDMGToCopy to OSXInstallESDName
- end if
- try
- tell me to do shell script "killall -9 'ASObjC Runner'"
- end try
- ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
- if OSXVersion is not "10.9" then
- tell me to do shell script "/usr/bin/rsync -rvpogWxtlE --exclude *tmp* --exclude /._Instructions.localized '/Volumes/" & MyDMGToCopy & "/' /Volumes/" & NewVolumeName & " &> /tmp/rsyncldm.log & "
- try
- repeat with i from 1 to 999999
- set RsyncStatus to (do shell script "ps auxc | grep rsync | wc -l | awk '{ print $1 }'")
- set RsyncFileCopied to (do shell script "tail -n 1 /tmp/rsyncldm.log")
- tell application "ASObjC Runner.app"
- set properties of «class aÂs8» to {«class aÂp2»:ASObjCMessageDetailCurrentLoc & RsyncFileCopied}
- if RsyncStatus is "0" then
- if DebugMode is false then
- tell me to do shell script "rm /tmp/rsyncldm.log"
- end if
- exit repeat
- end if
- end tell
- end repeat
- tell application "ASObjC Runner.app" to «event cÂc0cÂC0»
- tell me to do shell script "/usr/bin/rsync -rvpogWxtE '/Volumes/" & BaseSystemName & "/Applications/Utilities' /Volumes/" & NewVolumeName & " &> /tmp/rsyncldm.log &"
- on error
- RemoveTheCrubs()
- end try
- end if
- -- Now we copy the Utilities folder.
- ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
- if OSXVersion is not "10.9" then
- tell me to do shell script "/usr/bin/rsync -rvpogWxtE '/Volumes/" & BaseSystemName & "/Applications/Utilities' /Volumes/" & NewVolumeName & " &> /tmp/rsyncldm.log &"
- else
- tell me to do shell script "/usr/bin/rsync -rvpogWxtE '/Volumes/" & BaseSystemName & "/Applications/Utilities' '/Volumes/Install OS X Mavericks' &> /tmp/rsyncldm.log &"
- end if
- repeat with i from 1 to 999999
- set RsyncStatus to (do shell script "ps auxc | grep rsync | wc -l | awk '{ print $1 }'")
- delay 1
- tell application "ASObjC Runner.app"
- set RsyncFileCopied to (do shell script "tail -n 1 /tmp/rsyncldm.log")
- delay 1
- set properties of «class aÂs8» to {«class aÂp2»:ASObjCMessageDetailCurrentLoc & RsyncFileCopied}
- if RsyncStatus is "0" then
- tell me to do shell script "rm /tmp/rsyncldm.log"
- exit repeat
- end if
- end tell
- end repeat
- tell application "ASObjC Runner.app" to quit
- -- The disk image is now ejected.
- try
- tell me to do shell script "hdiutil eject '/Volumes/" & BaseSystemName & "'"
- delay 2
- tell me to do shell script "hdiutil eject '/Volumes/" & OSXInstallESDName & "'"
- delay 2
- end try
- -- We'll use now another title for this disk. Just for fun. And to make the rest of the script easier to program.
- tell application "Finder"
- if OSXVersion is "10.9" then
- set name of disk "Install OS X Mavericks" to FinalDiskName
- else
- set name of disk NewVolumeName to FinalDiskName
- end if
- -- If using a SSD, the script tries to get access to the disk using its new name, but the system may have not registered it properly yet !
- -- This delay prevents this problem.
- delay 5
- activate
- open disk FinalDiskName
- -------------------------------------------------------------------------------------------
- -- Let's make this disk cooler !
- -------------------------------------------------------------------------------------------
- end tell
- -- Hide most folders
- try
- tell me to do shell script "chflags hidden '/Volumes/" & FinalDiskName & "/Library' '/Volumes/" & FinalDiskName & "/private' '/Volumes/" & FinalDiskName & "/System'"
- end try
- try
- tell me to do shell script "chflags hidden '/Volumes/" & FinalDiskName & "/BaseSystem.dmg' '/Volumes/" & FinalDiskName & "/BaseSystem.chunklist' '/Volumes/" & FinalDiskName & "/boot.efi' '/Volumes/" & FinalDiskName & "/kernelcache' '/Volumes/" & FinalDiskName & "/mach_kernel' '/Volumes/" & FinalDiskName & "/usr' '/Volumes/" & FinalDiskName & "/Packages' '/Volumes/" & FinalDiskName & "/MacOSX_Media_Background.png'"
- end try
- -- Move the icons
- tell application "Finder"
- if OSXVersion = "10.9" then
- try
- set position of alias "OS X 10.9 Mavericks Install Disk:Install OS X Mavericks.app" to {413, 76}
- end try
- else
- if OSXVersion is "10.8" then
- try
- set position of alias "OS X Mountain Lion Install Disk:Install OS X Mountain Lion.app:" to {413, 76}
- end try
- else
- try
- set position of alias "Mac OS X Lion Install Disk:Install Mac OS X Lion.app:" to {413, 76}
- end try
- end if
- end if
- set position of folder "Utilities" of disk FinalDiskName to {413, 264}
- open disk FinalDiskName
- close front window
- open disk FinalDiskName
- set icon size of icon view options of front window to 128
- try
- set sidebar width of front window to 0
- end try
- set bounds of front window to {1, 44, 512, 484}
- end tell
- -- Apply background
- set BackgroundImage to path to resource OSXBackground in bundle (path to me)
- set BackgroundImagePath to quoted form of (POSIX path of BackgroundImage)
- tell me to do shell script "cp -R " & BackgroundImagePath & " '/Volumes/" & FinalDiskName & "'"
- tell application "Finder"
- try
- set background picture of icon view options of front window to file OSXBackground of disk FinalDiskName
- end try
- end tell
- tell me to do shell script "chflags hidden '/Volumes/" & FinalDiskName & "/" & OSXBackground & "'"
- try
- tell me to do shell script "touch '/Volumes/" & FinalDiskName & "/Utilities/.Localized'"
- end try
- -- We need to close and re-open the window to refresh position of icons. Known bug. Oh well…
- tell application "Finder"
- close front window
- open disk FinalDiskName
- end tell
- on error the error_message number the error_number
- set the error_text to MyAnErrorOccured & the error_number & ". " & the error_message
- display dialog MyDiskCouldNotBeCreatedError & error_text
- return
- end try
- -------------------------------------------------------------------------------------------
- -- Don't forget the custom icon ! --
- -------------------------------------------------------------------------------------------
- -- We copy the icon in the /tmp folder, otherwise AppleScript will complain that it won't be able to access the icon file inside the bundle. Oh well.
- set ZipIconPath to quoted form of ((POSIX path of (path to me) & "Contents/Resources/" & DiskIconName & ".zip"))
- try
- tell me to do shell script "cp -R " & ZipIconPath & " /tmp/"
- end try
- -- We could have used gzip or another command, but this was the only way to preserve the icon file on the picture.
- tell me to do shell script "open -a '/System/Library/CoreServices/Archive Utility.app' /private/tmp/" & DiskIconName & ".zip"
- delay 2
- try
- tell me to do shell script "killall -9 'Archive Utility'"
- end try
- -- We had to add some delay because SSDs may be too fast and not provide time to copy and paste the icon.
- delay 3
- try
- tell application "Finder"
- activate
- open information window of file ("private:tmp:" & DiskIconName & ".png") of startup disk
- end tell
- tell application "System Events"
- tell application process "Finder"
- tell front window
- keystroke tab
- delay 1
- keystroke "c" using command down
- keystroke "w" using command down
- end tell
- end tell
- end tell
- delay 1
- tell application "Finder"
- open information window of disk FinalDiskName
- end tell
- tell application "System Events"
- tell application process "Finder"
- tell front window
- delay 1
- keystroke tab
- delay 1
- keystroke "v" using command down
- delay 2
- keystroke "w" using command down
- end tell
- end tell
- end tell
- -- Too many icons errors with third-party utilities with decompression tools. In this case, we'll just leave the icon file on the Desktop.
- on error
- display dialog IconError1Loc & return & IconError2Loc & DiskIconName & IconError3Loc & return & return & IconError4Loc buttons ContinueButtonLoc
- tell me to do shell script "cp " & ZipIconPath & " ~/Desktop"
- end try
- tell application "Finder"
- try
- close window "tmp"
- end try
- -- We personnalize the disk name with OS version now
- try
- set CompleteDiskName to (InstallDiskNameLoc & " - " & OSXImageVersion)
- set name of disk FinalDiskName to CompleteDiskName
- end try
- end tell
- -- Let's delete the temporary icon.
- try
- tell me to do shell script "rm -f /tmp/" & DiskIconName & ".png"
- tell me to do shell script "rm -f /tmp/" & DiskIconName & ".zip"
- end try
- -- We create an invisible file with OS Version in it. Useful to re-use the disk rapidly.
- tell me to do shell script "echo " & OSXImageVersion & " &> " & quoted form of ("/Volumes/" & CompleteDiskName) & "/.LionDiskMaker_OSVersion"
- (********************************************************************
- ********************* VICTORY ! ********************
- ********************************************************************)
- with timeout of 9999 seconds
- -- Woohoo ! :)
- try
- tell me to do shell script ("afplay " & (quoted form of POSIX path of SoundPath))
- end try
- -- Display final dialog
- activate
- display dialog MyLionBootDiskIsReadyLoc & return & return & WannaMakeADonation buttons {QuitButtonLoc, StartupPrefLoc, MyMakeADonationLoc} default button 3 with icon path to resource IconName in bundle (path to me)
- set the button_pressed to the button returned of the result
- if the button_pressed is MyMakeADonationLoc then
- open location MyPaypalLoc
- return
- else
- if the button_pressed is StartupPrefLoc then
- tell me to do shell script "open '/System/Library/PreferencePanes/StartupDisk.prefPane'"
- end if
- end if
- end timeout
- end timeout
- -- End of the choice of method to create the disk --
- ---------------------------------------------------------------------------------------
- ------------------------------------- HANDLERS ------------------------------------
- ---------------------------------------------------------------------------------------
- -- RemoveTheCrubs Handler
- on RemoveTheCrubs()
- try
- tell me to do shell script "rm /tmp/rsyncldm.log"
- end try
- try
- tell me to do shell script "killall -9 rsync"
- end try
- delay 2
- try
- tell application "ASObjC Runner.app" to quit
- end try
- end RemoveTheCrubs
- -- Handler to manually choose an OS X install app or DMG.
- on theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
- set MyOSXFile to (choose file with prompt ChooseOSXFilePrompt1Loc & OSFileName & ChooseOSXFilePrompt2Loc)
- tell application "Finder"
- set MyOSXFileExtension to name extension of MyOSXFile
- end tell
- if MyOSXFileExtension is "app" then
- set OSX_App to quoted form of ((POSIX path of MyOSXFile))
- set OSX_DMG to quoted form of ((POSIX path of MyOSXFile) & "/Contents/SharedSupport/InstallESD.dmg")
- set OSXisFound to "Found"
- else
- if MyOSXFileExtension is "dmg" then
- set OSX_DMG to quoted form of (POSIX path of MyOSXFile)
- set OSXisFound to "Found"
- else
- display dialog MyNotTheCorrectOSXFileLoc buttons {CancelButtonLoc} with icon stop
- return
- end if
- end if
- end theChoiceOfAnotherCopy
- -- Handler to reset ASObjC Runner properties
- on ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
- try
- tell application "ASObjC Runner.app"
- «event aÂc0aÂC0»
- set properties of «class aÂs8» to {«class aÂp3»:"Cancel", «class aÂp4»:false, «class aÂp1»:ASObjCMessageLoc, «class aÂp2»:ASObjCMessageDetailLoc, «class aÂp7»:true, «class aÂp8»:9999, «class aÂpa»:0}
- «event bÂc0bÂC0»
- activate
- end tell
- end try
- delay 0.5
- end ResetAsojbCRunner
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement