-1

I have tried to use an AppleScript to reboot to Windows It's not going well though, as when I tried it the first time, a white screen appeared on startup and didn't go away. A hard reset rebooted to Yosemite. I have this script saved as an Application and in my Dock for instant restart, but it's been disappointing.

Here's the script:

set adminpass to "MYPASSWORDWENTHERE"

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

Can anyone help me get this thing to work?

  • Does booting into Windows work if you run bless ... directly in Terminal? – nohillside Mar 26 '15 at 7:46
  • I haven't tried doing that. I'm not very competent in running basic Terminal commands at the moment. If you can give me the command to run the "bless" command, I'll gladly try it...I'm going to try the answer below and see if that works. :) – JesusGeek35 Mar 26 '15 at 17:07
  • Open Terminal, enter sudo bless -mount /Volumes/BOOTCAMP/ -legacy -setBoot -nextonly; sudo shutdown -r now and press Return – nohillside Mar 26 '15 at 18:35
  • This booted directly into Mac, unfortunatley...I have a sneaking suspicion that my BOOTCAMP volume is corrupted, because now even when I hold Option and try to boot from there, all I get is a white screen for a long period, followed by a black screen for a long period. – JesusGeek35 Mar 28 '15 at 2:58
1

I tested this using Yosemite and it does work. I assume you are doing a BIOS boot for Windows. If you are doing an EFI boot, then this script will probably not work. BIOS booting is the traditional way that BootCamp installs Windows on Macs. I added an additional button to allow changing the default operating system to Windows.

You are aware that you can hold down the alt/option key at startup to select which operating system to boot to? I also assume, you know that the default boot operating system can be selected from the System Preferences in OS X and the Control Panel in Windows?

You can also install the free rEFInd boot manager. This product can produce an optional boot menu each time you start (or restart) your Mac. You can then select which operation system to boot to. If interested, let me know, and I will help you set up rEFInd.

set output to do shell script "diskutil list /dev/disk0"
repeat with row in paragraphs in output
    if row contains "Microsoft Basic Data" then
        set slice to last word in row

        set adminpass to "MYPASSWORDWENTHERE"

        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

        try
            set askRestart to display dialog "Restart in Windows?" buttons {"Cancel", "Once", "Always"} default button 1 with icon iconPath
        on error
            exit repeat
        end try
        set doRestart to button returned of askRestart

        if doRestart is in {"Restart", "Once", "Always"} then
            set command to "bless --device /dev/" & slice & " --legacy --setBoot"
            if doRestart is in {"Restart", "Once"} then
                set command to command & " --nextonly"
            end if
            set command to command & "; shutdown -r now"
            try
                do shell script command password adminpass with administrator privileges
            end try
        end if

        exit repeat
    end if
end repeat
| improve this answer | |
  • I have used rEFInd. Unfortunately, it doesn't work anymore. And even holding Option won't boot Windows. You can see my comment above for more info. – JesusGeek35 Apr 5 '15 at 3:26
0
do shell script "bless -mount /Volumes/WINDOWS/ -legacy -setBoot -nextonly" with administrator privileges
do shell script "shutdown -r now" with administrator privileges 

Replace WINOWS with the name of your bootcamp partition.

Source: Lifehacker.com

| improve this answer | |
  • This script rebooted directly into Yosemite, even when I changed the volume to BOOTCAMP and added my admin password. Going to try the "bless" Terminal script. – JesusGeek35 Mar 27 '15 at 2:37
  • Maybe try using terminal and removing -nextonly, see if that works. That way we can probably get closer to the problem. Have you checked if the volume is called bootcamp in /Volumes/ ? Caps matter as well I believe – Kevin Grabher Mar 27 '15 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .