Programmatic Time Zone Setting with OS X?

Peter Rukavina

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?

Comments

Submitted by Cody Swanson on

Permalink

Stolen from the OS X Server command line reference:

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

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

Submitted by Peter Rukavina on

Permalink

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.

Submitted by Eric Coffin on

Permalink

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.

- e.co

Add new comment

Plain text

  • Allowed HTML tags: <b> <i> <em> <strong> <blockquote> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

About This Blog

Photo of Peter RukavinaI am . I am a writer, letterpress printer, and a curious person.

To learn more about me, read my /nowlook at my bio, read presentations and speeches I’ve written, or get in touch (peter@rukavina.net is the quickest way). You can subscribe to an RSS feed of posts, an RSS feed of comments, or receive a daily digests of posts by email.

Search