Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2014
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.13 KB | None | 0 0
  1. global MyOSXFileExtension
  2. global OSX_App
  3. global OSX_DMG
  4. global OSXisFound
  5.  
  6. -- Version of DiskMaker X
  7.  
  8. set CurrentLDMVersion to "304"
  9.  
  10. set DebugMode to false
  11.  
  12. set LDMIcon to path to resource "LDM_Icon.icns" in bundle (path to me)
  13. set CurrentOS to do shell script "sw_vers -productVersion | cut -c 1-4"
  14.  
  15.  
  16. (*************************************************
  17. *** Strings declarations to allow localization ********
  18. *************************************************)
  19.  
  20.  
  21. -- Update dialog
  22.  
  23. set DialogUpdate1Loc to localized string of "A newer version of DiskMaker X is available. Do you want to download it?"
  24. set NotNowThanksLoc to localized string of "Not now, thanks"
  25. set GetNewVersionLoc to localized string of "Get new version"
  26.  
  27. -- New Version of OS X available dialog
  28.  
  29. 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."
  30. set LatestVersionLoc to localized string of "The latest version is:"
  31. set YourVersionLoc to localized string of "Your OS X Version is:"
  32. set NewOSXVersionDownload to localized string of "Download now from App Store"
  33. set NewOSXVersionNotYet to localized string of "Not now"
  34. 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."
  35.  
  36. -- Welcome Dialog
  37.  
  38. set WelcomeLoc to localized string of "Welcome to DiskMaker X!"
  39. set MyWhichOSXVersion to localized string of "Which version of OS X do you wish to make a boot disk of?"
  40.  
  41.  
  42. -- Copy found dialog
  43.  
  44. set AcopyofOSXwasfoundinfolderLoc to localized string of "I found a copy of the installer software in this folder:"
  45. set DoyouwishtousethiscopyLoc to localized string of "Do you wish to use this copy?"
  46.  
  47.  
  48. set MyUseAnotherCopy to localized string of "Use another copy…"
  49. set MyUseThisCopyLoc to localized string of "Use this copy"
  50.  
  51.  
  52. -- Some standard buttons
  53.  
  54. set QuitButtonLoc to localized string of "Quit"
  55. set CancelButtonLoc to localized string of "Cancel"
  56. set ContinueButtonLoc to localized string of "Continue"
  57.  
  58.  
  59. -- No installer found dialog
  60.  
  61. set LDMDiskDetectedLoc1 to localized string of "I detected that the following disk was already built with DiskMaker X:"
  62. set LDMDiskDetectedLoc2 to localized string of "Do you want to use it to build your new install disk ?"
  63.  
  64. 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."
  65.  
  66.  
  67. set ChooseOSXFileLoc to localized string of "Select an Install file…"
  68. set ChooseOSXFilePrompt1Loc to localized string of "Select "
  69. set ChooseOSXFilePrompt2Loc to localized string of " OR the InstallESD.dmg file only :"
  70.  
  71.  
  72. set MyCheckTheFaq to localized string of "Check the FAQ"
  73. 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."
  74.  
  75. 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."
  76. set MyMakeADonationLoc to localized string of "Make a donation"
  77. set MyWebSite to localized string of "http://liondiskmaker.com/"
  78. set WannaMakeADonation to localized string of "If you enjoyed using DiskMaker X, your donations are also much appreciated."
  79. set StartupPrefLoc to localized string of "Open Startup Disk Preference"
  80.  
  81. -- Error dialog
  82.  
  83. set MyDiskCouldNotBeCreatedError to localized string of "The disk could not be created because of an error: "
  84. set MyAnErrorOccured to localized string of "An error occured: "
  85. set MyUseThisDisk to localized string of "Use this disk"
  86. set MyEraseAndCreateTheDisk to localized string of "Erase then create the disk"
  87.  
  88. -- Kind of physical disk dialog
  89.  
  90. set WhichKindOfDiskYouUseLoc to localized string of "Which kind of disk will you use?"
  91. 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."
  92. set WhichKindOfDiskIsUSB8GBLoc to localized string of "An 8 GB USB thumb drive"
  93. set WhichKindOfDiskIsAnyOtherDiskLoc to localized string of "Another kind of disk"
  94.  
  95.  
  96. -- Last alert dialog
  97.  
  98. set LastAlertMessageLocVolume to localized string of "WARNING ! THE WHOLE CONTENTS OF THIS VOLUME WILL BE ERASED!"
  99. set LastAlertMessageLocDisc to localized string of "WARNING: THE WHOLE CONTENT OF THE DISK (AND EVERY OTHER VOLUME OF THIS DISK) WILL BE ERASED!"
  100. set LastAlertPart1Loc to localized string of "You are about to erase the volume : "
  101. 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 ?"
  102. set LastAlertPart3Loc to localized string of "The following volumes are on the same disk and will be erased:"
  103.  
  104. -- Alert for Mavericks
  105.  
  106. set MavericksAdminAlertLoc to localized string of "You will be required to type your login and password soon."
  107.  
  108. 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."
  109.  
  110.  
  111. -- Can't use this disk dialog
  112.  
  113. set MyNotTheCorrectOSXFileLoc to localized string of "This file can't be used to create a Lion Installation disk."
  114.  
  115. -- Disk selection dialog
  116.  
  117. set HereAreTheDisksLoc to localized string of "Here are the disks you may want to use to create your boot disk"
  118. set ChooseDiskToErase to localized string of "Please choose the disk you wish to erase"
  119. set ChooseThisDiskLoc to localized string of "Choose this disk"
  120.  
  121.  
  122. -- Miscellanous localizations
  123.  
  124. set MyCantUseThisDisk to localized string of "This disk can't be used because it is not a removable disk."
  125. set ChooseDiskToEraseLoc to localized string of "Please choose the disk you wish to erase"
  126.  
  127.  
  128. -- No disk available alert
  129.  
  130. set NoDiskAvailableLoc to localized string of "Sorry, I can't find a disk to use… Please plug a disk, then relaunch DiskMaker X."
  131.  
  132. -- Icon Error Management
  133.  
  134. 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."
  135. set IconError2Loc to localized string of "I will leave a copy of the compressed icon named "
  136. set IconError3Loc to localized string of ".zip on your Desktop so that you can still personnalize the disk yourself."
  137. set IconError4Loc to localized string of "Check the FAQ on the web site for more info."
  138.  
  139.  
  140.  
  141. -- ASObjcC strings for activity bar
  142.  
  143. set ASObjCMessageLoc to localized string of "Please wait, DiskMaker X is copying files…"
  144. set ASObjCMessageDetailLoc to localized string of "This may take a while… Be patient !"
  145. set ASObjCMessageDetailCurrentLoc to localized string of "Copying file: "
  146.  
  147.  
  148.  
  149. 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 ?"
  150. set AlreadyALDMDiskConfirmLoc to localized string of "Update this volume"
  151. set AlreadyALDMDiskCancelLoc to localized string of "User another volume"
  152.  
  153. set CopyingFilesLoc to localized string of "Copying files…"
  154.  
  155. set MyPaypalLoc to localized string of "http://liondiskmaker.com/?page_id=149"
  156.  
  157. 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."
  158. set MoreInfoButtonLoc to localized string of "More information"
  159. 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."
  160.  
  161. set OpenAppStoreLoc to localized string of "Open App Store"
  162.  
  163. -- Path to sound resource
  164.  
  165. set SoundPath to ((path to resource "woohoo.mp3"))
  166.  
  167. -- Check if a new version is available. Should have been done sooner.
  168.  
  169. try
  170. with timeout of 10 seconds
  171.  
  172. set LatestLDMVersion to do shell script "curl http://liondiskmaker.com/CurrentLDMVersion" as string
  173. if LatestLDMVersion is greater than CurrentLDMVersion then
  174.  
  175. display dialog DialogUpdate1Loc buttons {QuitButtonLoc, NotNowThanksLoc, GetNewVersionLoc} default button 3
  176.  
  177. set ResultButton to the button returned of the result
  178.  
  179. if ResultButton is GetNewVersionLoc then
  180. open location MyWebSite
  181. return
  182. else
  183. if ResultButton is QuitButtonLoc then
  184. return
  185. end if
  186. end if
  187. end if
  188. end timeout
  189. end try
  190.  
  191.  
  192.  
  193. ## 03/08/12 : added this line to prevent some ASObC Runner issues
  194.  
  195. try
  196. tell me to do shell script "killall -9 'ASObjC Runner'"
  197. end try
  198.  
  199.  
  200.  
  201. -- We copy the pref file for ASobjCRunner in Prefs folder. Makes things easier for later.
  202. -- I tried to use the ASObjCRunner-N tip to avoid displaying the alerts, but DiskMaker X does not
  203. -- work properly then :-/
  204.  
  205. -- If you have better ways to do it, I welcome suggestions :)
  206.  
  207. set Prefpath to (path to preferences folder)
  208. set PosixPrefPath to (quoted form of POSIX path of Prefpath)
  209. set SourcePrefPath to (quoted form of POSIX path of (path to resource "au.com.myriad-com.ASObjC-Runner.plist"))
  210.  
  211. delay 1
  212.  
  213. try
  214. tell me to do shell script "cp -R " & SourcePrefPath & " " & PosixPrefPath
  215. end try
  216.  
  217. -- Then we can call ASObjCRunner.app which is enclosed in the bundle
  218.  
  219. set runnerPath to (path to resource "ASObjC Runner.app")
  220.  
  221. ## 03/08/12 : modified "& to " & - Seems to improve error with ASObjC Runner
  222.  
  223. tell me to do shell script "open " & (quoted form of POSIX path of runnerPath) & " &> /dev/null &"
  224. activate
  225.  
  226. -- First, we ask which OS we want to deal with so that we can declare a few variables.
  227.  
  228.  
  229. 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)
  230. set the button_pressed to the button returned of the result
  231.  
  232.  
  233. if the button_pressed is "Mavericks (10.9)" then
  234. if CurrentOS is "10.6" then
  235. display dialog MyNotOSX106CompatibleLoc buttons {QuitButtonLoc, MoreInfoButtonLoc} default button 2 with icon path to resource IconName in bundle (path to me)
  236. set the button_pressed to the button returned of the result
  237. if button_pressed is MoreInfoButtonLoc then
  238. open location "http://liondiskmaker.com/?page_id=28"
  239. else
  240. return
  241. end if
  242. return
  243. end if
  244.  
  245. -- Variables for OS X 10.9 (aka "Mavericks")
  246.  
  247. set OSXVersion to "10.9"
  248. set OSFileName to "Install OS X Mavericks"
  249. set IconName to "Maverick.icns"
  250. set DiskIconName to "MaverickDiskIcon512"
  251. set FinalDiskName to "OS X 10.9 Mavericks Install Disk"
  252. set InstallDiskNameLoc to localized string of "OS X 10.9 Install Disk"
  253. set OSXInstallESDName to "OS X Install ESD"
  254. set BaseSystemName to "OS X Base System"
  255. set OSXBackground to "MavericksBackground.png"
  256.  
  257. else
  258. if the button_pressed is "Mountain Lion (10.8)" then
  259.  
  260. -- Variables for Mountain Lion
  261.  
  262. set OSXVersion to "10.8"
  263. set OSFileName to "Install OS X Mountain Lion"
  264. set IconName to "MountainLion.icns"
  265. set DiskIconName to "MLDiskIcon512"
  266. set FinalDiskName to "OS X Mountain Lion Install Disk"
  267. set InstallDiskNameLoc to localized string of "OS X Mountain Lion Install Disk"
  268. set OSXInstallESDName to "Mac OS X Install ESD"
  269. set BaseSystemName to "Mac OS X Base System"
  270. set OSXBackground to "MountainLion_Background.png"
  271.  
  272. else
  273.  
  274. -- Variables for Lion
  275. set OSXVersion to "10.7"
  276. set OSFileName to "Install Mac OS X Lion"
  277. set IconName to "Lion.icns"
  278. set DiskIconName to "LionDiskIcon512"
  279. set FinalDiskName to "Mac OS X Lion Install Disk"
  280. set InstallDiskNameLoc to localized string of "OS X Lion Install Disk"
  281. set OSXInstallESDName to "Mac OS X Install ESD"
  282. set BaseSystemName to "Mac OS X Base System"
  283. set OSXBackground to "MountainLion_Background.png"
  284.  
  285. end if
  286. end if
  287.  
  288.  
  289.  
  290. -- First I check if I can find the install app in the Applications folder.
  291. -- I will use Spotlight only if it does not exist here.
  292.  
  293. set OSXisFound to "Not found yet"
  294.  
  295. tell application "System Events"
  296. if exists file ("/Applications/" & OSFileName & ".app/Contents/SharedSupport/InstallESD.dmg") then
  297. set OSX_DMG to "'/Applications/" & OSFileName & ".app/Contents/SharedSupport/InstallESD.dmg'"
  298.  
  299. if OSXVersion is "10.9" then
  300. set OSX_App to quoted form of "/Applications/Install OS X Mavericks.app"
  301. end if
  302. set OSXisFound to "Found"
  303. 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)
  304. set the button_pressed to the button returned of the result
  305.  
  306. -- If it's not the right app, you may want to choose another app.
  307.  
  308. if the button_pressed is MyUseThisCopyLoc then
  309.  
  310. set OSX_DMG to quoted form of ("/Applications/" & OSFileName & ".app/Contents/SharedSupport/InstallESD.dmg")
  311. set OSXisFound to "Found"
  312. set OSX_App to quoted form of ("/Applications/" & OSFileName & ".app")
  313. else
  314. if the button_pressed is MyUseAnotherCopy then
  315.  
  316. my theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
  317.  
  318. end if
  319.  
  320. if the button_pressed is CancelButtonLoc then
  321. return
  322. end if
  323. end if
  324. end if
  325. end tell
  326.  
  327.  
  328. -- If we can't find in /Applications, then we use Spotlight
  329.  
  330. if OSXisFound is "Not found yet" then
  331.  
  332. set OSSearch to (do shell script "mdfind -name '" & OSFileName & "' | grep -v Library | head -1")
  333. set OSSearchResultNumber to (do shell script "echo " & OSSearch & " | wc -l ") as integer
  334.  
  335.  
  336. if OSSearch is not "" then
  337.  
  338. set OSXFolder to OSSearch
  339. 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)
  340. set the button_pressed to the button returned of the result
  341.  
  342. if the button_pressed is MyUseThisCopyLoc then
  343.  
  344. if OSXVersion is "10.9" then
  345. set OSX_App to quoted form of (POSIX path of OSXFolder)
  346. set OSX_DMG to quoted form of ((POSIX path of OSXFolder) & "/Contents/SharedSupport/InstallESD.dmg")
  347. else
  348. set OSX_DMG to quoted form of ((POSIX path of OSXFolder) & "/Contents/SharedSupport/InstallESD.dmg")
  349. end if
  350. else
  351. if the button_pressed is MyUseAnotherCopy then
  352.  
  353. my theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
  354. end if
  355.  
  356. if the button_pressed is CancelButtonLoc then
  357. return
  358. end if
  359.  
  360. end if
  361.  
  362. else
  363. display dialog MyCouldNotFoundInstallOSXAppLoc buttons {CancelButtonLoc, MyCheckTheFaq, ChooseOSXFileLoc} default button 3 with icon caution
  364.  
  365. set the button_pressed to the button returned of the result
  366.  
  367. if the button_pressed is MyCheckTheFaq then
  368. open location MyWebSite
  369. return
  370. else
  371. if the button_pressed is ChooseOSXFileLoc then
  372.  
  373. my theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
  374.  
  375. end if
  376.  
  377. end if
  378.  
  379. end if
  380. end if
  381.  
  382.  
  383.  
  384.  
  385.  
  386. (********************* Creating a bootable disc ***************************)
  387.  
  388.  
  389. -- New routine checks if a file exists with a .LionDiskMaker_OSVersion hidden file at root.
  390.  
  391. tell application "Finder"
  392. set DontEraseTheDisk to false
  393. set LDMAlreadyThere to false
  394.  
  395. set TheNumberOfEjectableDisks to the number of (every disk whose (ejectable is true))
  396.  
  397. try
  398. set TheEjectableDiskList to the name of (every disk whose (ejectable is true))
  399. on error
  400. display dialog "No removable disk found !"
  401. return
  402.  
  403. end try
  404. set n to 1
  405.  
  406. repeat with loopVar from n to TheNumberOfEjectableDisks
  407. set MyDisk to (item n of TheEjectableDiskList)
  408. set HiddenFileToFind to "/Volumes/" & MyDisk & "/.LionDiskMaker_OSVersion" as string
  409. if exists HiddenFileToFind as POSIX file then
  410. set LDMAlreadyThere to true
  411. set NewVolumeName to MyDisk
  412. set AlreadyLDMDisk to MyDisk
  413. set MyErasefullDisc to false
  414. end if
  415.  
  416. set n to n + 1
  417. end repeat
  418. end tell
  419.  
  420. if LDMAlreadyThere is true then
  421. activate
  422. 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)
  423. set the button_pressed to the button returned of the result
  424. if the button_pressed is AlreadyALDMDiskConfirmLoc then
  425. set MyTargetDisk to AlreadyLDMDisk
  426. set MyTargetDiskPath to the quoted form of (POSIX path of MyTargetDisk)
  427. else
  428. set LDMAlreadyThere to false
  429. end if
  430. end if
  431.  
  432.  
  433. if LDMAlreadyThere is false then
  434. -- 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.
  435. activate
  436. display alert WhichKindOfDiskYouUseLoc message WhichKindOfDiskExplainationLoc & return & return buttons {CancelButtonLoc, WhichKindOfDiskIsAnyOtherDiskLoc, WhichKindOfDiskIsUSB8GBLoc} default button 3 as critical
  437. set the button_pressed to the button returned of the result
  438. if the button_pressed is WhichKindOfDiskIsUSB8GBLoc then
  439. set MyErasefullDisc to true
  440. else
  441. if the button_pressed is WhichKindOfDiskIsAnyOtherDiskLoc then
  442. set MyErasefullDisc to false
  443. else
  444. return
  445. end if
  446. end if
  447.  
  448. -- We have to define the list of disks available for use.
  449.  
  450.  
  451. tell application "Finder"
  452. if MyErasefullDisc is true then
  453. try
  454. set ListOfDisks to the name of (every disk whose (ejectable is true) and (capacity is less than 8.5E+10))
  455. on error
  456. display dialog NoDiskAvailableLoc buttons {QuitButtonLoc} default button 1 with icon path to resource IconName in bundle (path to me)
  457. return
  458. end try
  459. set LastAlertMessageLoc to LastAlertMessageLocDisc
  460. else
  461. try
  462. set ListOfDisks to the name of (every disk whose (ejectable is true))
  463. on error
  464. display dialog NoDiskAvailableLoc buttons {QuitButtonLoc} default button 1 with icon path to resource IconName in bundle (path to me)
  465. return
  466. end try
  467. set LastAlertMessageLoc to LastAlertMessageLocVolume
  468. end if
  469. end tell
  470.  
  471. 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
  472. if MyTargetDisk is not false then
  473. set MyTargetDiskPath to the quoted form of (POSIX path of MyTargetDisk)
  474. else
  475. display dialog NoDiskAvailableLoc buttons {QuitButtonLoc} default button 1 with icon path to resource IconName in bundle (path to me)
  476.  
  477. return
  478. end if
  479.  
  480. -- We get all the volumes which are part of the same disk as our target volume. Just to let the user know…
  481.  
  482. set FullDiskName to do shell script "diskutil info " & quoted form of (MyTargetDisk as string) & " | grep 'Part Of Whole' | awk '{ print $4 }'"
  483.  
  484. -- And we get the full size of the disk. Necessary a bit later.
  485. -- thanks @lolopb who managed to find a way to workaround a bad limitation with diskutil in 10.6…
  486.  
  487. if MyErasefullDisc is true then
  488. try
  489. 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'"
  490. on error errMsg number errNum
  491. set FullListOfDisks to ""
  492. set LastAlertPart2Loc to ""
  493. set LastAlertPart3Loc to ""
  494. end try
  495. else
  496. set FullListOfDisks to ""
  497. set LastAlertPart3Loc to ""
  498. end if
  499.  
  500. -- Last Warning !!! There's no turning back from here.
  501.  
  502. display alert LastAlertMessageLoc message LastAlertPart1Loc & return & return & MyTargetDisk & return & return & LastAlertPart2Loc & return & LastAlertPart3Loc & return & return & FullListOfDisks buttons {CancelButtonLoc, MyEraseAndCreateTheDisk} default button 2 as warning
  503.  
  504. set the button_pressed to the button returned of the result
  505. if the button_pressed is CancelButtonLoc then
  506. return
  507. end if
  508. end if
  509.  
  510. if OSXVersion is "10.9" then
  511. display alert MavericksAdminAlertTitleLoc message MavericksAdminAlertLoc buttons {CancelButtonLoc, ContinueButtonLoc} default button 2 as warning
  512. end if
  513.  
  514. -- Disk creations begins ! --
  515.  
  516. -- We use uuidgen to warrant a unique name to the disk (avoiding to erase other drives in the process…)
  517. if DontEraseTheDisk is false then
  518.  
  519. set NewVolumeName to (do shell script "uuidgen")
  520.  
  521. -- To avoid errors, we check that the disk is really ejectable.
  522.  
  523. set IsEjectable to do shell script "diskutil info " & MyTargetDiskPath & " | grep -i \"Ejectable\" | awk '{ print $2}' "
  524. if IsEjectable is "No" then
  525.  
  526. display dialog MyCantUseThisDisk with icon stop
  527.  
  528. else
  529.  
  530. -- 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+.
  531. if MyErasefullDisc is true then
  532.  
  533. tell me to do shell script "diskutil partitionDisk $(diskutil info " & MyTargetDiskPath & " | grep -i \"Part Of Whole\" | awk '{ print $4}') 1 GPT jhfs+ " & NewVolumeName & " R"
  534. else
  535. tell me to do shell script "diskutil eraseVolume JHFS+ " & NewVolumeName & " " & MyTargetDiskPath
  536. end if
  537.  
  538. end if
  539.  
  540. end if
  541.  
  542. -- sometimes the volume is not mounted yet while the copy begins. We need to delay a bit...
  543.  
  544. delay 2
  545.  
  546.  
  547. with timeout of 9999 seconds
  548.  
  549. -- First, we unmount any occurence of the Base System and the OS X Install ESD disk. Just in case.
  550.  
  551. try
  552. tell me to do shell script "hdiutil detach '/Volumes/" & BaseSystemName & "'"
  553. delay 2
  554. end try
  555.  
  556. try
  557. tell me to do shell script "hdiutil detach '/Volumes/" & OSXInstallESDName & "'"
  558. delay 2
  559. end try
  560.  
  561.  
  562.  
  563. try
  564. -- We mount the InstallESD image as read only, without showing it in the Finder (thanks Lolopb ;-) )
  565.  
  566. try
  567. tell me to do shell script "hdiutil attach " & OSX_DMG & " -noverify -nobrowse"
  568. on error
  569. display dialog DMGIncompleteLoc buttons {QuitButtonLoc, OpenAppStoreLoc} default button 2
  570. set the button_pressed to the button returned of the result
  571. if the button_pressed is OpenAppStoreLoc then
  572. tell application "App Store.app" to activate
  573. end if
  574. return
  575. end try
  576.  
  577.  
  578. -- Then we mount the hidden BaseSystem.DMG file to get the System Version and copy the Utilities folder later.
  579. try
  580. tell me to do shell script "hdiutil attach '/Volumes/" & OSXInstallESDName & "/BaseSystem.dmg' -noverify -nobrowse"
  581. on error
  582. display dialog DMGIncompleteLoc buttons {QuitButtonLoc, OpenAppStoreLoc} default button 2
  583. set the button_pressed to the button returned of the result
  584. if the button_pressed is OpenAppStoreLoc then
  585. tell application "App Store.app" to activate
  586. end if
  587. return
  588. end try
  589.  
  590. -- We get the version number. We will use it to rename the USB disk properly later.
  591.  
  592.  
  593. set OSXImageVersion to (do shell script "defaults read '/Volumes/" & BaseSystemName & "/System/Library/CoreServices/SystemVersion' ProductVersion") as string
  594.  
  595. tell application "Finder"
  596. open disk NewVolumeName
  597.  
  598. -- 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.
  599. try
  600. «event BATFchck»
  601. on error
  602. set bounds of Finder window 1 to {1, 44, 503, 493}
  603. set sidebar width of Finder window 1 to 0
  604. set statusbar visible of Finder window 1 to true
  605. set current view of Finder window 1 to icon view
  606. end try
  607.  
  608.  
  609. end tell
  610. (*********************************************************************************************************************************)
  611.  
  612. -- There are great differences between Mavericks and previous versions of OS X.
  613. -- If we deal with Mavericks, we use now a built-in command provided by Apple. It requires admin authorization though.
  614.  
  615. if OSXVersion is "10.9" then
  616.  
  617.  
  618. try
  619. tell me to do shell script "killall -9 'ASObjC Runner'"
  620. end try
  621.  
  622. delay 1
  623. ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
  624.  
  625. activate
  626. 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
  627.  
  628. try
  629.  
  630. repeat with i from 1 to 999999
  631. set CreateInstallMediaStatus to (do shell script "ps auxc | grep createinstallmedia | wc -l | awk '{ print $1 }'")
  632. set CreateInstallMediaLog to (do shell script "tail -n 1 /tmp/createinstallmedia.log")
  633. set CheckIfDiskIsErased to (do shell script "tail -n 1 /tmp/createinstallmedia.log | grep '100%' | wc -l | cut -c 8")
  634. if CheckIfDiskIsErased is "1" then
  635. set CreateInstallMediaLog to CopyingFilesLoc
  636. end if
  637.  
  638. tell application "ASObjC Runner.app"
  639. set properties of «class aÂs8» to {«class aÂp2»:CreateInstallMediaLog}
  640. if CreateInstallMediaLog is "Done." then
  641.  
  642. if DebugMode is false then
  643. tell me to do shell script "rm /tmp/rsyncldm.log"
  644. end if
  645. exit repeat
  646.  
  647. end if
  648.  
  649. end tell
  650. end repeat
  651.  
  652. tell application "ASObjC Runner.app" to «event cÂc0cÂC0»
  653.  
  654.  
  655. on error
  656. RemoveTheCrubs()
  657. end try
  658.  
  659. --tell application "Finder"
  660. -- set name of disk "Install OS X Mavericks" to NewVolumeName
  661. --end tell
  662. else
  663. set MyDMGToCopy to OSXInstallESDName
  664. end if
  665.  
  666. try
  667. tell me to do shell script "killall -9 'ASObjC Runner'"
  668. end try
  669.  
  670.  
  671. ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
  672.  
  673. if OSXVersion is not "10.9" then
  674.  
  675.  
  676.  
  677.  
  678. tell me to do shell script "/usr/bin/rsync -rvpogWxtlE --exclude *tmp* --exclude /._Instructions.localized '/Volumes/" & MyDMGToCopy & "/' /Volumes/" & NewVolumeName & " &> /tmp/rsyncldm.log & "
  679.  
  680. try
  681.  
  682. repeat with i from 1 to 999999
  683. set RsyncStatus to (do shell script "ps auxc | grep rsync | wc -l | awk '{ print $1 }'")
  684. set RsyncFileCopied to (do shell script "tail -n 1 /tmp/rsyncldm.log")
  685.  
  686. tell application "ASObjC Runner.app"
  687.  
  688. set properties of «class aÂs8» to {«class aÂp2»:ASObjCMessageDetailCurrentLoc & RsyncFileCopied}
  689. if RsyncStatus is "0" then
  690.  
  691. if DebugMode is false then
  692. tell me to do shell script "rm /tmp/rsyncldm.log"
  693. end if
  694. exit repeat
  695.  
  696. end if
  697.  
  698. end tell
  699. end repeat
  700.  
  701. tell application "ASObjC Runner.app" to «event cÂc0cÂC0»
  702.  
  703. tell me to do shell script "/usr/bin/rsync -rvpogWxtE '/Volumes/" & BaseSystemName & "/Applications/Utilities' /Volumes/" & NewVolumeName & " &> /tmp/rsyncldm.log &"
  704.  
  705. on error
  706. RemoveTheCrubs()
  707. end try
  708. end if
  709.  
  710.  
  711. -- Now we copy the Utilities folder.
  712.  
  713. ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
  714.  
  715. if OSXVersion is not "10.9" then
  716. tell me to do shell script "/usr/bin/rsync -rvpogWxtE '/Volumes/" & BaseSystemName & "/Applications/Utilities' /Volumes/" & NewVolumeName & " &> /tmp/rsyncldm.log &"
  717.  
  718. else
  719. tell me to do shell script "/usr/bin/rsync -rvpogWxtE '/Volumes/" & BaseSystemName & "/Applications/Utilities' '/Volumes/Install OS X Mavericks' &> /tmp/rsyncldm.log &"
  720.  
  721. end if
  722. repeat with i from 1 to 999999
  723. set RsyncStatus to (do shell script "ps auxc | grep rsync | wc -l | awk '{ print $1 }'")
  724. delay 1
  725. tell application "ASObjC Runner.app"
  726.  
  727. set RsyncFileCopied to (do shell script "tail -n 1 /tmp/rsyncldm.log")
  728. delay 1
  729. set properties of «class aÂs8» to {«class aÂp2»:ASObjCMessageDetailCurrentLoc & RsyncFileCopied}
  730.  
  731. if RsyncStatus is "0" then
  732. tell me to do shell script "rm /tmp/rsyncldm.log"
  733. exit repeat
  734. end if
  735.  
  736. end tell
  737. end repeat
  738.  
  739. tell application "ASObjC Runner.app" to quit
  740.  
  741.  
  742. -- The disk image is now ejected.
  743. try
  744. tell me to do shell script "hdiutil eject '/Volumes/" & BaseSystemName & "'"
  745.  
  746. delay 2
  747. tell me to do shell script "hdiutil eject '/Volumes/" & OSXInstallESDName & "'"
  748.  
  749. delay 2
  750. end try
  751.  
  752.  
  753. -- We'll use now another title for this disk. Just for fun. And to make the rest of the script easier to program.
  754.  
  755. tell application "Finder"
  756. if OSXVersion is "10.9" then
  757. set name of disk "Install OS X Mavericks" to FinalDiskName
  758. else
  759. set name of disk NewVolumeName to FinalDiskName
  760.  
  761. end if
  762. -- 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 !
  763. -- This delay prevents this problem.
  764.  
  765. delay 5
  766. activate
  767. open disk FinalDiskName
  768.  
  769.  
  770. -------------------------------------------------------------------------------------------
  771. -- Let's make this disk cooler !
  772. -------------------------------------------------------------------------------------------
  773. end tell
  774.  
  775.  
  776. -- Hide most folders
  777.  
  778. try
  779. tell me to do shell script "chflags hidden '/Volumes/" & FinalDiskName & "/Library' '/Volumes/" & FinalDiskName & "/private' '/Volumes/" & FinalDiskName & "/System'"
  780. end try
  781. try
  782. 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'"
  783. end try
  784.  
  785. -- Move the icons
  786.  
  787. tell application "Finder"
  788. if OSXVersion = "10.9" then
  789. try
  790. set position of alias "OS X 10.9 Mavericks Install Disk:Install OS X Mavericks.app" to {413, 76}
  791. end try
  792. else
  793. if OSXVersion is "10.8" then
  794.  
  795. try
  796. set position of alias "OS X Mountain Lion Install Disk:Install OS X Mountain Lion.app:" to {413, 76}
  797. end try
  798.  
  799. else
  800. try
  801. set position of alias "Mac OS X Lion Install Disk:Install Mac OS X Lion.app:" to {413, 76}
  802. end try
  803. end if
  804. end if
  805.  
  806.  
  807. set position of folder "Utilities" of disk FinalDiskName to {413, 264}
  808.  
  809.  
  810. open disk FinalDiskName
  811. close front window
  812. open disk FinalDiskName
  813. set icon size of icon view options of front window to 128
  814.  
  815. try
  816. set sidebar width of front window to 0
  817. end try
  818. set bounds of front window to {1, 44, 512, 484}
  819. end tell
  820.  
  821.  
  822.  
  823. -- Apply background
  824.  
  825. set BackgroundImage to path to resource OSXBackground in bundle (path to me)
  826. set BackgroundImagePath to quoted form of (POSIX path of BackgroundImage)
  827.  
  828. tell me to do shell script "cp -R " & BackgroundImagePath & " '/Volumes/" & FinalDiskName & "'"
  829.  
  830. tell application "Finder"
  831. try
  832. set background picture of icon view options of front window to file OSXBackground of disk FinalDiskName
  833. end try
  834. end tell
  835.  
  836. tell me to do shell script "chflags hidden '/Volumes/" & FinalDiskName & "/" & OSXBackground & "'"
  837.  
  838. try
  839. tell me to do shell script "touch '/Volumes/" & FinalDiskName & "/Utilities/.Localized'"
  840. end try
  841.  
  842.  
  843.  
  844. -- We need to close and re-open the window to refresh position of icons. Known bug. Oh well…
  845.  
  846. tell application "Finder"
  847. close front window
  848. open disk FinalDiskName
  849. end tell
  850.  
  851. on error the error_message number the error_number
  852. set the error_text to MyAnErrorOccured & the error_number & ". " & the error_message
  853.  
  854. display dialog MyDiskCouldNotBeCreatedError & error_text
  855. return
  856. end try
  857.  
  858. -------------------------------------------------------------------------------------------
  859. -- Don't forget the custom icon ! --
  860. -------------------------------------------------------------------------------------------
  861.  
  862. -- 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.
  863.  
  864. set ZipIconPath to quoted form of ((POSIX path of (path to me) & "Contents/Resources/" & DiskIconName & ".zip"))
  865.  
  866. try
  867. tell me to do shell script "cp -R " & ZipIconPath & " /tmp/"
  868. end try
  869.  
  870. -- We could have used gzip or another command, but this was the only way to preserve the icon file on the picture.
  871.  
  872. tell me to do shell script "open -a '/System/Library/CoreServices/Archive Utility.app' /private/tmp/" & DiskIconName & ".zip"
  873. delay 2
  874.  
  875. try
  876. tell me to do shell script "killall -9 'Archive Utility'"
  877. end try
  878.  
  879. -- We had to add some delay because SSDs may be too fast and not provide time to copy and paste the icon.
  880.  
  881. delay 3
  882.  
  883. try
  884. tell application "Finder"
  885. activate
  886.  
  887. open information window of file ("private:tmp:" & DiskIconName & ".png") of startup disk
  888.  
  889. end tell
  890.  
  891.  
  892. tell application "System Events"
  893. tell application process "Finder"
  894. tell front window
  895. keystroke tab
  896. delay 1
  897. keystroke "c" using command down
  898. keystroke "w" using command down
  899. end tell
  900. end tell
  901. end tell
  902. delay 1
  903.  
  904. tell application "Finder"
  905. open information window of disk FinalDiskName
  906. end tell
  907.  
  908. tell application "System Events"
  909. tell application process "Finder"
  910. tell front window
  911. delay 1
  912. keystroke tab
  913. delay 1
  914. keystroke "v" using command down
  915. delay 2
  916.  
  917. keystroke "w" using command down
  918. end tell
  919. end tell
  920. end tell
  921.  
  922.  
  923. -- Too many icons errors with third-party utilities with decompression tools. In this case, we'll just leave the icon file on the Desktop.
  924.  
  925. on error
  926. display dialog IconError1Loc & return & IconError2Loc & DiskIconName & IconError3Loc & return & return & IconError4Loc buttons ContinueButtonLoc
  927. tell me to do shell script "cp " & ZipIconPath & " ~/Desktop"
  928.  
  929. end try
  930.  
  931. tell application "Finder"
  932. try
  933. close window "tmp"
  934. end try
  935.  
  936. -- We personnalize the disk name with OS version now
  937.  
  938. try
  939. set CompleteDiskName to (InstallDiskNameLoc & " - " & OSXImageVersion)
  940. set name of disk FinalDiskName to CompleteDiskName
  941. end try
  942. end tell
  943.  
  944.  
  945. -- Let's delete the temporary icon.
  946.  
  947. try
  948. tell me to do shell script "rm -f /tmp/" & DiskIconName & ".png"
  949. tell me to do shell script "rm -f /tmp/" & DiskIconName & ".zip"
  950. end try
  951.  
  952. -- We create an invisible file with OS Version in it. Useful to re-use the disk rapidly.
  953.  
  954. tell me to do shell script "echo " & OSXImageVersion & " &> " & quoted form of ("/Volumes/" & CompleteDiskName) & "/.LionDiskMaker_OSVersion"
  955.  
  956.  
  957. (********************************************************************
  958. ********************* VICTORY ! ********************
  959. ********************************************************************)
  960.  
  961.  
  962. with timeout of 9999 seconds
  963. -- Woohoo ! :)
  964. try
  965.  
  966. tell me to do shell script ("afplay " & (quoted form of POSIX path of SoundPath))
  967. end try
  968.  
  969. -- Display final dialog
  970. activate
  971. display dialog MyLionBootDiskIsReadyLoc & return & return & WannaMakeADonation buttons {QuitButtonLoc, StartupPrefLoc, MyMakeADonationLoc} default button 3 with icon path to resource IconName in bundle (path to me)
  972. set the button_pressed to the button returned of the result
  973. if the button_pressed is MyMakeADonationLoc then
  974. open location MyPaypalLoc
  975. return
  976. else
  977. if the button_pressed is StartupPrefLoc then
  978. tell me to do shell script "open '/System/Library/PreferencePanes/StartupDisk.prefPane'"
  979. end if
  980. end if
  981.  
  982. end timeout
  983.  
  984. end timeout
  985.  
  986. -- End of the choice of method to create the disk --
  987.  
  988.  
  989.  
  990. ---------------------------------------------------------------------------------------
  991. ------------------------------------- HANDLERS ------------------------------------
  992. ---------------------------------------------------------------------------------------
  993.  
  994.  
  995. -- RemoveTheCrubs Handler
  996.  
  997. on RemoveTheCrubs()
  998. try
  999. tell me to do shell script "rm /tmp/rsyncldm.log"
  1000. end try
  1001. try
  1002. tell me to do shell script "killall -9 rsync"
  1003. end try
  1004. delay 2
  1005.  
  1006. try
  1007. tell application "ASObjC Runner.app" to quit
  1008. end try
  1009.  
  1010. end RemoveTheCrubs
  1011.  
  1012. -- Handler to manually choose an OS X install app or DMG.
  1013.  
  1014. on theChoiceOfAnotherCopy(ChooseOSXFilePrompt1Loc, OSFileName, ChooseOSXFilePrompt2Loc, MyNotTheCorrectOSXFileLoc, CancelButtonLoc)
  1015. set MyOSXFile to (choose file with prompt ChooseOSXFilePrompt1Loc & OSFileName & ChooseOSXFilePrompt2Loc)
  1016.  
  1017. tell application "Finder"
  1018. set MyOSXFileExtension to name extension of MyOSXFile
  1019. end tell
  1020.  
  1021. if MyOSXFileExtension is "app" then
  1022. set OSX_App to quoted form of ((POSIX path of MyOSXFile))
  1023. set OSX_DMG to quoted form of ((POSIX path of MyOSXFile) & "/Contents/SharedSupport/InstallESD.dmg")
  1024. set OSXisFound to "Found"
  1025.  
  1026. else
  1027.  
  1028. if MyOSXFileExtension is "dmg" then
  1029. set OSX_DMG to quoted form of (POSIX path of MyOSXFile)
  1030. set OSXisFound to "Found"
  1031.  
  1032. else
  1033. display dialog MyNotTheCorrectOSXFileLoc buttons {CancelButtonLoc} with icon stop
  1034. return
  1035. end if
  1036. end if
  1037.  
  1038. end theChoiceOfAnotherCopy
  1039.  
  1040. -- Handler to reset ASObjC Runner properties
  1041.  
  1042. on ResetAsojbCRunner(ASObjCMessageLoc, ASObjCMessageDetailLoc)
  1043.  
  1044. try
  1045. tell application "ASObjC Runner.app"
  1046. «event aÂc0aÂC0»
  1047. 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}
  1048. «event bÂc0bÂC0»
  1049. activate
  1050. end tell
  1051. end try
  1052. delay 0.5
  1053. end ResetAsojbCRunner
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement