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.
- From the Apple menu, choose System Preferences.
- Click Date & Time.
- Make sure the Set date & time automatically box is checked.
- Start Script Editor (which is usually located in the AppleScript folder in your Applications folder).
- From the File menu, choose New.
- Type or paste the following code:
tell application "System Preferences"
reveal pane "Date & Time"
end tell
delay 5
quit - Click Compile in the toolbar to make sure there are no problems with your code.
- You can try it out live by clicking Run, too.
- Back in Script Editor, choose Save As ... from the File menu.
- Enter a name like Set Clock Automatically.
- Choose a location to save the app. (I put mine in the Utilities folder inside my Applications folder.)
- From the File Format drop-down, select Application.
- Click Save.
- You can quit Script Editor, if you want.
- From the Apple menu, choose System Preferences.
- Click Show All, then click Accounts.
- In the left pane, click the name that corresponds to your user account.
- Click the Login Items tab.
- Click the + button below the list of applications.
- Find and select the application you saved in steps 6-10.
- Click Add.
- 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.













Reader Comments (Page 1 of 2)
6-03-2008 @ 8:37PM
Rubbinz said...
Thanks Robert! I use Boot Camp too and usually just open the date/time settings and let it reset it but it gets annoying sometimes.
Reply
6-04-2008 @ 3:28AM
m3hm3t said...
Thanks this was very informative..
6-03-2008 @ 8:41PM
TVGenius said...
Sweet. Ever since I got my 1st-gen 20-inch iMac fixed by Apple, the clock more or less runs backwards when it's asleep, and never auto-updates, I have to uncheck and recheck it in Time prefs.
Reply
6-03-2008 @ 9:20PM
Gregory Homyak said...
Thank you!!!! I hate how this happens with Boot Camp, it is so annoying. Another great tip from TUAW!
Reply
6-03-2008 @ 9:28PM
James said...
or even easier. Set your windows time zone to GMT and set the time. Windows won't bother to reset it to what the actual GMT time is and os x will get the time it likes. No script. Much easier. I didn't think of this obviously simple fix. But I can't remember who told me.
Reply
6-03-2008 @ 9:56PM
Tony Williams said...
An even easier solution is to get the network time protocol daemon to do the work for you. It doesn't do it now as it doesn't like resetting your time if it is out by a large margin but you can tell it to ignore the margin.
Open the Terminal and, if you have admin rights, this line fixes it :-
sudo printf "\nntpd -g -q\n" >> /etc/rc.local
which adds a line to one of the shell scripts run at boot (the first, in fact, which doesn't exist by default) and whenever you boot your Mac the time server will be checked and your time fixed.
The advantage of this fix is that if you have Active Directory logins the time will be fixed before the Login Window comes up and a bad time can upset AD.
# Tony Williams
http://honestpuck.blogspot.com/
Reply
6-04-2008 @ 12:39AM
michas_pi said...
Kick ass, this fixed it!
Thank you, good sir.
6-05-2008 @ 1:07AM
GrizzlyAdams said...
Except rc.local is depreciated in favor of launchd in Leopard. There is a helper called Lingon that will write the launchd xml files for you though.
6-04-2008 @ 5:42AM
Klaus T. said...
Mr. Tony W.,
Could you please clarify a bit about this line:
"Open the Terminal and, if you have admin rights, this line fixes it"
Because when I try to do it, I get an error:
KT-MacBookPro:~ klaus$ sudo printf "\nntpd -g -q\n" >> /etc/rc.local
-bash: /etc/rc.local: Permission denied
Shouldn't the SUDO command automatically ask me for my password and then give access?
6-04-2008 @ 6:58AM
niknak said...
Me too, even when i'm logged in as administrator. What are we doing wrong?
6-10-2008 @ 11:23AM
KiltBear said...
first do a
sudo su -
and THEN do the command without the "sudo" in front of it.
What happens is that
sudo somecommand >> outputfile
will run "somecommand" with privileges, but will attempt to put the results of that command into "outputfile" AFTER the command is finished. So it is trying to append the output after you no longer have the permissions to do so.
6-04-2008 @ 11:33PM
Tony Williams said...
Sorry for the delay answering, I've been ill overnight.
I have no idea why it worked for me yesterday when I checked.
Kiltbear is right - do a 'sudo -s' to get a root shell and then just write to the file.
6-03-2008 @ 10:07PM
Beau said...
Well, I used one of those 'hairy' registry fixes without any problems :-)
Easier, especially when I'm not connected to teh interwebz.
Reply
6-03-2008 @ 11:59PM
Court Kizer said...
There's actually the Mother of All Bugs in OS X since nearly the 10.1 It's complicated but certain prefs after a disgraceful reboot or something like bootcamp will be lost.
On notebooks it's ambient brightness, and automatic time. Drives ME INSANE, does it on all 50+ notebooks I've owned, and I can reproduce it on anybody's mac notebook.
Reply
6-04-2008 @ 1:21AM
whatever said...
sigh.
i hate it when 'gurus' attempt to 'fix' a problem and end up making an unholy, godawful mess of it, like here.
seriously, did you put any effort into researching timekeeping in Mac OS X before writing the script and this article?
as a previous poster says, it's a one-liner. An alternative is to edit the ntpd config file since the ntpd runs in the background permanently anyway, and as stated, does not perform an update if the error margin is too high.
a one-liner. that is run once. then forget about it.
compare that to "open sys prefs every time your computer boots. wait a minute. close it." even if it's scripted - that's not a solution. that's not even a hack. that's just retarded.
Reply
6-04-2008 @ 1:38AM
Rafe H. said...
You must be really small or something.
6-04-2008 @ 9:34AM
Robert Palmer said...
Your full refund is in the mail.
6-05-2008 @ 2:19AM
whatever said...
it's not about sending *me* a refund. i knew better to start with.
send it to all the poor suckers that think you're an authority on the subject and who just went through a 22-step bogus solution instead of doing it the right (sane) way.
PS: Rafe H, be that as it may, it's curious that my post is the only three-star ranked one out of all the comments here. clearly a lot of other people are silently small, too.
6-04-2008 @ 3:49AM
Arnan de Gans said...
It seems you lot have trouble with this,
I myself use Bootcamp, WXP and Leopard 10.5.3 almost daily and never have trouble with the time. I have both OS'es set to GMT+1 and on both auto updating the time with time.euro.apple.com is set (yes on windows too!)
Reply
6-04-2008 @ 4:07AM
Jason P said...
i never noticed that bug! the joys of living in GMT
Reply