Programmatic Time Zone Setting with OS X?

It occurs to me that because the Plazes Launcher API returns the time zone of the current Plaze, I could add functionality to my primitive little Ruby launcher that would automatically set my OS X time zone as I move about the country.

Problem is that I can’t seem to figure out how to programmatically set the time zone using OS X. Does anyone have information on how to do so, either from the command line, or using Applescript?


Cody Swanson's picture
Cody Swanson on August 23, 2005 - 22:31

Stolen from the OS X Server command line reference:

To view the current timezone:
$ sudo systemsetup -gettimezone
$ serversetup -getTimeZone
To view the available time zones:
$ sudo systemsetup -listtimezones
To change the system time zone:
$ sudo systemsetup -settimezone timezone
$ sudo serversetup -setTimeZone timezone

If that doesn’t work check /etc/ for timezone or zones, most Unixes store timezone info in /etc.

Peter Rukavina's picture
Peter Rukavina on August 24, 2005 - 00:10

As this hint says, these utilities — systemsetup and serversetup — are only included in OS X Server, although you can, as the hint goes on to explain, grab them from the freely available Remote Desktop application.

Eric Coffin's picture
Eric Coffin on August 24, 2005 - 22:38

I believe this should do: (Achieved using 10.4.2)

The directory /usr/share/zoneinfo contains directories lisiting, I suppose for all the timezones in the world — categorized by Country as well for our localized timezone names (eg. /usr/share/zoneinfo/Canada/Atlantic is a file that contains our timezone information. Not sure of the actual encoding used here. Luckily I didn’t have to modify these files.

The other directory we are interested in is /etc/ . Within this
directory is a file called localtime. It is a symbolic link pointing to some file with /usr/share/zoneinfo/ . I found the following /etc/localtime→/usr/share/zoneinfo/Canada/Atlantic.

I sudo removed the file /etc/localtime/.

I sudo’d again and used the command ln -s
/usr/share/zoneinfo/Canada/Mountain localtime . To create a symbolic link called localtime pointing to the appropriate timezone file.

Once the symbolic link has been updated the date/time/location changes. I didn’t figure out how to refresh the clock though —  Opening up date&time settings will do it. Likely the system will as well, but not instantaneously. Perhaps a call to gettime?

I reckon there’s your hook.

Time to get back to the Future.


Add new comment