Filed under: Tips and tricks, TUAW Tips
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.
- 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.
Get a WordPress.com Blog
![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 2)
Rubbinz said 8:37PM on 6-03-2008
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
m3hm3t said 3:28AM on 6-04-2008
Thanks this was very informative..
TVGenius said 8:41PM on 6-03-2008
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
James said 9:28PM on 6-03-2008
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
Gregory Homyak said 9:20PM on 6-03-2008
Thank you!!!! I hate how this happens with Boot Camp, it is so annoying. Another great tip from TUAW!
Reply
Stuart said 9:16PM on 6-04-2008
The other way is to write a windows .bat file in Notepad like this and put it in the Start/ Start programs folder to execute when you boot into windows. This works in Vista perfectly.
w32tm /resync
exit
Then when you restart in OS X the time is correct
Now if someone can tell me how to get my Apple Wireless Keyboard to pair at bootup I'll be a happy man.
Reply
Tony Williams said 9:56PM on 6-03-2008
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
michas_pi said 12:39AM on 6-04-2008
Kick ass, this fixed it!
Thank you, good sir.
GrizzlyAdams said 1:07AM on 6-05-2008
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.
Klaus T. said 5:42AM on 6-04-2008
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?
niknak said 6:58AM on 6-04-2008
Me too, even when i'm logged in as administrator. What are we doing wrong?
KiltBear said 11:23AM on 6-10-2008
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.
Tony Williams said 11:33PM on 6-04-2008
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.
Beau said 10:07PM on 6-03-2008
Well, I used one of those 'hairy' registry fixes without any problems :-)
Easier, especially when I'm not connected to teh interwebz.
Reply
Court Kizer said 11:59PM on 6-03-2008
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
whatever said 1:21AM on 6-04-2008
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
Rafe H. said 1:38AM on 6-04-2008
You must be really small or something.
Robert Palmer said 9:34AM on 6-04-2008
Your full refund is in the mail.
whatever said 2:19AM on 6-05-2008
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.
Arnan de Gans said 3:49AM on 6-04-2008
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