Advertisement
applehelpwriter

make a Sierra USB installer

Aug 21st, 2016
1,483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###########################################################
  2. # ABOUT
  3. ###########################################################
  4. (*
  5.  
  6.  Phil Stokes -- 2016
  7.  applehelpwriter.com
  8.  sqwarq.com
  9.  
  10. *)
  11. ###########################################################
  12. # DESCRIPTION
  13. ###########################################################
  14. (*
  15.  
  16. This script will make a bootable USB installer from a Sierra beta installer
  17. Requires Admin privileges
  18.  
  19. *)
  20. ###########################################################
  21. # USAGE
  22. ###########################################################
  23. (*
  24.  
  25. Download the installer made available to you by Apple
  26. Insert a blank 16GB USB into your mac
  27. Run the script and specify the locations of the installer and the USB
  28. Note the script continues to run until the installer has been created.
  29. It sleeps for an interval of 10 secs between checking the job status.
  30.  
  31. *)
  32. ###########################################################
  33. # IMPORT STATEMENTS
  34. ###########################################################
  35.  
  36. use AppleScript version "2.5"
  37. use scripting additions
  38. use framework "Foundation"
  39.  
  40.  
  41. ###########################################################
  42. # VARIABLES
  43. ###########################################################
  44.  
  45. property NSString : a reference to current application's NSString
  46. property NSCaseInsensitiveSearch : a reference to 1
  47. set isDone to false
  48.  
  49.  
  50. ###########################################################
  51. # HANDLERS
  52. ###########################################################
  53.  
  54.  
  55. on escapeSpaces(aString)
  56.     set this_string to aString as text
  57.     if this_string contains " " then
  58.         set theReplace to "\\ "
  59.         set theFind to " "
  60.         set str to NSString's stringWithString:this_string
  61.         set this_string to (str's stringByReplacingOccurrencesOfString:theFind withString:theReplace options:NSCaseInsensitiveSearch range:{0, str's |length|()}) as text
  62.         set aString to this_string
  63.     end if
  64.     return aString
  65. end escapeSpaces
  66.  
  67.  
  68.  
  69. ###########################################################
  70. # COMMANDS
  71. ###########################################################
  72.  
  73. set theInstaller to POSIX path of (choose file with prompt "Choose the Installer app" default location (path to applications folder) without showing package contents)
  74. set theThumb to POSIX path of (choose folder with prompt "Choose the USB drive" default location (path to startup disk))
  75. set theThumb to theThumb's text 1 thru -2
  76. set confirmMsg to "Are you sure you want to create a bootable USB drive with " & return & theInstaller & " on " & theThumb & "?"
  77.  
  78. if button returned of (display dialog confirmMsg buttons {"Cancel", "OK"} default button "OK" with title "MakeUSBInstaller script" with icon 1) is "OK" then
  79.    
  80.    
  81.     set theThumb to escapeSpaces(theThumb)
  82.     set theThumb to " --volume " & theThumb
  83.     set theInstaller to escapeSpaces(theInstaller)
  84.     set appPath to " --applicationpath " & theInstaller & " --nointeraction"
  85.     set inBackground to " &> /dev/null &"
  86.    
  87.     set execPath to "Contents/Resources/createinstallmedia"
  88.     set theInstaller to theInstaller & execPath
  89.     set createInstallMedia to theInstaller & theThumb & appPath
  90.    
  91.     do shell script createInstallMedia & inBackground with administrator privileges
  92.     delay 10
  93.     repeat while isDone is false
  94.         try
  95.             do shell script "ps ax | grep -v grep | grep createinstallmedia"
  96.             if the result contains "createInstallMedia" then
  97.                 delay 10
  98.             else
  99.                 set isDone to true
  100.             end if
  101.         on error
  102.             set isDone to true
  103.         end try
  104.     end repeat
  105.     if isDone is true then
  106.         display dialog "USB Install Media is done" buttons "OK" default button "OK" with title "MakeUSBInstaller script" with icon 1
  107.     end if
  108. end if
  109.  
  110.  
  111. ###########################################################
  112. #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement