One-click BootCamp activation using AppleScript and Keychain

Another in a series of “I better post this before I forget how I did it? code snippets.

Switching from a bootcamp Windows partition back to OSX is easy; there’s an icon in the system tray you can click and just choose “restart in Mac OS X”. Going the other way around is not so simple: you either have to open System Preferences, find Startup Disk, select your windows partition, and click Restart; or you have to reboot and hold down the Alt key and hope that it pops up the OS picker which I don’t know about you but for me that only works about one time in ten — most of the time it just goes straight back into OSX and I have to wait through the whole boot process before I can try again.

You can download BootChamp if you don’t mind cluttering your menubar with another icon, or Flipside which is better than the default, but still not quite handsfree.

Or you can save this AppleScript snippet as an application, and trigger it using Quicksilver or Spotlight or the Dock or however else you feel like doing it.

NOTE: This was originally posted using a different (and much stupider) technique. This way is better, because it doesn’t require you to muck around in Keychain Access manually.

Tested only in OS10.5; might or might not work for you without tweaking. For your convenience I’m making a compiled version of this script available — use it at your own risk. If you have any problems with it, though, let me know and I’ll try to fix it.

One final warning: This reboots by force-quitting every application immediately. This has the benefit of not leaving the system hanging there waiting for you to click Safari’s irritating “You still have a window open; are you sure you want to quit?” alert — but if you are running any applications which become unhappy when they don’t exit cleanly, remember to quit them before running this.