[Pythonmac-SIG] Apple Events

Corran Webster cwebster@nevada.edu
Fri, 14 Apr 2000 15:43:39 -0700


At 3:17 PM -0700 14/4/00, John W Baxter wrote:
> Dan Green enquires:
>
> >Does anybody know how to convert apple event types of "ldt" to a proper date
> >value? Whenever I capture said value in a python script I get a value of
> >
> >Unknown('ltd', '\000\000\000\000\265\034\246\343') or something similar.
> >
> >Dates on a Mac should be # of seconds since 1980 sometime, no?
> >
> >--
> >Dan Green           | "So What? It's your problem to learn to live with,
>
> 'ldt ' (note the trailing space) is the type used by AppleScript (and
> probably others) for the Macintosh long date type, which is a 64-bit signed
> number of seconds since the midnight at the beginning of January 1, 1904.
>
> It can be easily represented in C in one of the ways the Apple headers do
> it:  an unsigned long low longword and a signed long high longword.
>
> Sorry, but I haven't tried dealing with it in Python...I suppose a C
> extension could fabricate a suitable Python long integer.

The struct module should be sufficient:  something like

import struct, time
a, b = struct.unpack('lL', '\000\000\000\000\265\034\246\343')
secs = long(a) << 32 + b
print time.ctime(secs), time.asctime(time.gmtime(secs))

With this string I get the values 'Mon Apr 15 10:43:47 1996' and 'Mon Apr
15 17:43:47 1996' respectively.

You can use something like this in reverse to pack times into an Apple
Event, too, I would guess.


Regards,
Corran