Advertisement

TUAW Tip: Setting your clock automatically after using Boot Camp

I use Boot Camp pretty regularly, and one thing that always annoyed me about booting back into the world of the living the Mac was that my clock was always eight hours behind (I live in the Pacific time zone). Windows likes to set the system clock to my local time of GMT –8. Mac OS X, on the other hand, likes to keep the hardware clock at GMT, and set it "softly" using the operating system software. There are some hairy registry fixes for the Windows behavior, but they're unsupported.

While manually setting my clock back for the eleventy billionth time, I noticed that just opening and closing the Date & Time preference pane sets the clock automatically. Of course, I had to be connected to the Internet, and have the "set date & time automatically" checkbox selected.

Sensing an opportunity to make my life easier, I wrote myself an AppleScript that simply opens the Date & Time preference pane, leaves it open for a few seconds, and then closes it. I saved it as an application, and set it to run at startup.

That way, by the time my computer is finished booting, the clock is right, and I didn't have to even think about it.

After the jump, some code and instructions on how to do this yourself.

Here's how you can create a helper app like this to set your clock automatically every time your computer boots.

  1. From the Apple menu, choose System Preferences.

  2. Click Date & Time.

  3. Make sure the Set date & time automatically box is checked.

  4. Start Script Editor (which is usually located in the AppleScript folder in your Applications folder).

  5. From the File menu, choose New.

  6. Type or paste the following code:


    tell application "System Preferences"
    end tell

    reveal pane "Date & Time"
    delay 5
    quit

  7. Click Compile in the toolbar to make sure there are no problems with your code.

  8. You can try it out live by clicking Run, too.

  9. Back in Script Editor, choose Save As ... from the File menu.

  10. Enter a name like Set Clock Automatically.

  11. Choose a location to save the app. (I put mine in the Utilities folder inside my Applications folder.)

  12. From the File Format drop-down, select Application.

  13. Click Save.

  14. You can quit Script Editor, if you want.

  15. From the Apple menu, choose System Preferences.

  16. Click Show All, then click Accounts.

  17. In the left pane, click the name that corresponds to your user account.

  18. Click the Login Items tab.

  19. Click the + button below the list of applications.

  20. Find and select the application you saved in steps 6-10.

  21. Click Add.

  22. You can quit System Preferences, if you want.

As a wise author once said, "do these steps, and then you're done." Make sure you're connected to the Internet, and then give it a try by restarting into Windows, and restarting back into Mac OS X.

I've been using this script with Mac OS X 10.4 "Tiger" and 10.5 "Leopard," and have had no problems.