AppleScript to Reboot into Windows

If you’re running Boot Camp, it can be a pain to restart your Mac running Windows: you either have to go to Startup Disk preference pane and change your startup disk or you have to remember to hold down the “option” key when you start up your computer and then click on your Windows disk to start from it.

From the Windows side, it’s easy: Apple provides a Boot Camp app that runs in the task bar. All you have to do is right-click it and choose “Restart in OS X” and you’re good to go. Why can’t it be that easy under OS X?

With the AppleScript I came up with, it is!

Be advised that I am not an AppleScript expert. I pieced this together from code snippets I found on the Internet and changed to meet my needs. It works for me. There is no guarantee that it will work for you. I am not liable if it does not work for you or if it damages your computer or data. Proceed at your own risk! You may use this code free of charge for any purpose.

set adminpass to "YOURPASSWORDHERE"
 
tell application "Finder"
	set iconPath to (get name of startup disk) & ":Applications:Utilities:Boot Camp Assistant.app:Contents:Resources:DA.icns" as alias
end tell
 
set askRestart to display dialog "Restart in Windows?" buttons {"Cancel", "Restart"} default button 1 with icon iconPath
set doRestart to button returned of askRestart
 
if doRestart is equal to "Cancel" then
	quit
end if
 
if doRestart is equal to "Restart" then
	do shell script "bless -mount /Volumes/BOOTCAMP/ -legacy -setBoot -nextonly; shutdown -r now" password adminpass with administrator privileges
end if

Open This Code in AppleScript Editor and change the text YOURPASSWORDHERE to your administrator password. If you’ve changed the name of your Boot Camp volume, you’ll need to change BOOTCAMP on line 15 to the name of your Boot Camp Volume.

Once you’ve done this, just save as an Application to somewhere convenient then drag it to your Dock. When you click on it, you’ll get this:

 

restart in windows_20111001122600

Click the “Restart” button to restart your Mac running Windows or click the “Cancel” button to quit this app.


Comments

2 responses to “AppleScript to Reboot into Windows”

  1. Jacob Gunther Avatar
    Jacob Gunther

    Doesn’t work, just restarts back into OS X. Can anyone help?

    1. Your account is an administrator account? And you put in your password and volume name?