Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Choose startup disk via AppleScript System
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.]
    •    
  • Currently 4.33 / 5
  You rated: 5 / 5 (6 votes cast)
 
[24,585 views]  

Choose startup disk via AppleScript | 10 comments | Create New Account
Click here to return to the 'Choose startup disk via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Choose startup disk via AppleScript
Authored by: adrianm on Jan 29, '07 08:09:14AM
Also useful is setting the --nextonly flag to bless.

It tells an EFI (so, Intel) Mac to only boot from the specified volume on the next boot only.

Useful if you want to just dive into another OS and back.

---
~/.sig: not found

[ Reply to This | # ]

Choose startup disk via AppleScript
Authored by: Swordfish on Jan 29, '07 08:41:06AM

Thanks alot! Exactly what I was looking for (the --nextonly flag)!



[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: Swordfish on Jan 29, '07 11:43:56AM
iMac Core Duo (Early 2006):

-If I'm booting in Windows by default and I want to change the boot drive to Mac OS X, the script works fine.
-If I'm booting in Mac OS X by default and I want to use the script to switch to Windows, the script doesn't work (the system just reboots in OS X).

What gives?

PS: the --nextflag option also works when Windows is default and I want to go in OS X, but not when OS X is default and I want to go in Windows!

[ Reply to This | # ]

Choose startup disk via AppleScript
Authored by: AJB on Jan 29, '07 12:24:03PM

How do you run an AppleScript if you are booted into Windows???

Or do you mean, the default boot drive is Windows, but you happen to have booted into OS X, and this scrip works?

I'm not sure if bless is will handle setting Windows volumes (I've never run Boot Camp on my mac). You might want to check out the --bootefi option



[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: Swordfish on Jan 29, '07 02:19:38PM

I'll explain what I did, what worked and what didn't.

===
Booted in OS X
Default startup disk is Windows
I run the script (to boot in OS X)
The computer reboots in OS X **script is working**
===
Booted in OS X
Default startup disk is Macintosh HD
I run the script (to boot in Windows)
The computer reboots in OS X **script fails**
===
Booted in OS X
Default startup disk is Windows
I run the script (to boot in OS X) with --nextonly
The computer reboots in OS X once
The computer boots in Windows on the following reboots **script is working**
===
Booted in OS X
Default startup disk is Macintosh HD
I run the script (to boot in Windows) with --nextonly
The computer reboots in OS X **script fails**

BTW, I think the problem is not the Applescript itself, but the command line actions.



[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: Greville on Jan 30, '07 01:39:21AM
Hi Swordfish, You need to add the -legacy option, I use the following to reboot into windows:
do shell script "bless -mount /Volumes/yourWindowsVolume/ -legacy -setBoot -nextonly" password "yourPassword" with administrator privileges
do shell script "shutdown -r now" password "yourPassword" with administrator privileges
Just replace 'yourWindowsVolume' with your Bootcamp partition and 'yourPassword' with your admin password. NOTE: Having your admin password in plain text like this creates security issues for publicly accessible machines. If this is a concern you can lock down access to the script or simply remove 'password "yourPassword"' and the script will prompt people for the password.

[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: Swordfish on Jan 30, '07 03:37:12PM

You are awesome! Many thanks, works like a charm! :)



[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: flammable on Jan 29, '07 01:47:01PM

I found it easier to just drag into the dock:

/System/Library/PreferencePanes/StartupDisk.prefPane

A couple clicks, and you're rebooting onto another partition/drive. :)



[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: Oceanhints1 on Jan 29, '07 02:02:20PM

or you could use rEFIT.

http://refit.sourceforge.net/



[ Reply to This | # ]
Choose startup disk via AppleScript
Authored by: gordonlbuchanan on Jan 30, '07 01:04:46PM

Also, to get back to OSX from Windows, you can drag Startup Disk from the Windows control panel onto the desktop. It creates a link which you can use to quickly get back to OSX



[ Reply to This | # ]