I am making one app that can run AppleScript via NSAppleScript. Everything had been fine but I haven't been able to figure out how to pass date information from my app to AppleScript. (Since AppleScript has date type, I suppose this is possible) The way I pass parameters to AppleScript is through NSAppleEventDescriptor. I learned from Google that I could pass it as typeLongDateTime type:
- (id)initWithDate:(NSDate *)date {
LongDateTime ldt;
UCConvertCFAbsoluteTimeToLongDateTime(CFDateGetAbsoluteTime((CFDateRef)date), &ldt);
return [self initWithDescriptorType:typeLongDateTime
bytes:&ldt
length:sizeof(ldt)];
}
Unfortunately, the type LongDateTime had long gone, because I am using Swift and under OS X 10.10. Even the Core Services function UCConvertCFAbsoluteTimeToLongDateTime has already been removed from 10.10.3.
Now I am stuck.
Do you have any ideas that inspire?
Is seems that
LongDateTime
is a signed 64-bit integer which represents a dated
as the number of seconds since January 1, 1904, GMT, adjusted by the time-zone offset ford
in the local time zone (including daylight-savings time offset if DST is active atd
).The following code gives the same result as your Objective-C code for all dates that I tested (winter time and summer time).
Update for Swift 3:
Update for macOS 10.11:
As of macOS 10.11 there is a
initializer, so that the above workaround is no longer necessary. (Thanks to @Wevah for this information.)