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

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

October 1, 2011 at 12:26pm | 2 Comments
Tagged: , , and

2 Comments so far

  1. Joel, on October 1, 2011 at 6:48pm, said:

    Haven't been able to get it to work. My volume is /Volumes/Windows, and that's the only thing I can think that might be causing an issue. Is there any log I can look at to figure out what is going on?

    Edit Comment

  2. Randy, on October 2, 2011 at 6:07pm, said:

    Make sure the change /Volumes/BOOTCAMP/ to /Volumes/Windows/ on line 15 (remember the trailing slash)

    Edit Comment

Leave a comment?
« Barbecue Chicken Pizza  —  Cake Anytime »

Recent Comments

Monthly Archives

More...

Tags

More...