Choose startup disk via AppleScript

Jan 29, '07 07:30:03AM

Contributed by: tkw4u

I have a machine that I've partitioned into several different areas. I've installed different versions of OS X on them, and boot between them to test things. I got tired of having to go to System Preferences, select the startup disc, clicking restart, etc., so I found a way to do it using the command line.

The actual command line method is...

bless -mount "/Volumes/name of the disc" -setBoot
...where name of the disc is the actual name of the hard drive, i.e. Macintosh HD.

I put this, as well as a restart, into an AppleScript and stuck the script on the various partitions. Now it takes me a click and a password to reboot into another partition. You can save it in ~/Library/Scripts to have access through the Scripts menu in the menu bar, or save it as an application and just place it on the desktop.

The two line version below can be used when you know which disc you'll be booting to. Just copy it into Script Editor and replace "Name of the drive" with the name of your hard drive:
do shell script ¬
 "bless -mount \"/Volumes/Name of the drive\" -setBoot" ¬
 with administrator privileges
do shell script "shutdown -r now" with administrator privileges
Another version (which I use) will let you choose which partition using buttons:
display dialog "Select a startup disk" buttons ¬
 {"name of disc 1", "name of disc 2"}
set bootVol to the button returned of the result as text
do shell script "bless -mount \"/Volumes/" & bootVol & ¬
 "\" -setBoot" with administrator privileges
do shell script "shutdown -r now" with administrator privileges
[robg adds: While the Option key can be held at startup to choose a boot drive, it takes some time as the machine scans and lists the bootable drives. By using a script to specify the startup disk, you won't have to wait during reboot.]

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20070126131322301