Getting dates from NSAppleEventDescriptor

This is more a Cocoa question, but I was hoping someone here might know the answer…

I’m trying to convert my ASOC app to Cocoa - it reads in data from a task app via applescript and displays it in a tableview.

After getting the data using NSAppleScript I am able to successfully access text fields using the ‘stringValue’ method for NSAppleEventDescriptor. e.g.

But I can’t figure out how to extract a date from NSAppleEventDescriptor:

The only reference to this I’ve found refers to this project as the solution: This doesn’t appear straightforward to include in my app, so I was hoping there was another solution.


ldt is of type LongDateTime which is in fact an integer value (SInt64).
You have to convert ldt to absolute time.
As NSAppleEventDescriptor does not support anymore the longDateTimeValue method, get the raw data.

This Cocoa code should work

- (NSDate *)dateFromEventDescriptor:(NSAppleEventDescriptor *)descriptor
	NSDate *resultDate = nil;
	OSStatus status;
	CFAbsoluteTime absoluteTime;
	LongDateTime longDateTime;
	if ([descriptor descriptorType] == typeLongDateTime) {
		[[descriptor data] getBytes:&longDateTime length:sizeof(longDateTime)];
		status = UCConvertLongDateTimeToCFAbsoluteTime(longDateTime, &absoluteTime);
		if (status == noErr) {
			resultDate = [(NSDate *)CFDateCreate(NULL, absoluteTime) autorelease];
	return resultDate;

That worked perfectly! Thank you so much StefanK - I would never have figured that out.