The following code is working. It's expected to return the app last launch date, but...
// e.g. entryPath = @"/Applications/Evernote.app"
struct stat output;
int ret = stat([entryPath fileSystemRepresentation], &output);
if (ret == 0)
{
struct timespec accessTime = output.st_atimespec;
NSDate * date1 = [[NSDate dateWithTimeIntervalSince1970:accessTime.tv_sec]
dateWithCalendarFormat:nil timeZone:[NSTimeZone localTimeZone]];
// and the 10.6+ version: (the result was always the same for me)
NSDate * date2 = [[[[NSURL fileURLWithPath:entryPath]
resourceValuesForKeys:[NSArray arrayWithObject:NSURLContentAccessDateKey]
error:nil]
objectForKey:NSURLContentAccessDateKey]
dateWithCalendarFormat:nil timeZone:[NSTimeZone localTimeZone]];
}
It returns very strange dates, usually near 3:00-3:30 AM, today or yesterday, when I was actually sleeping. But after that, I click "Get Info" in Finder, and it shows the real last launch date (which is usually less than date1
and date2
, but can be also equal). How to get it programmatically?