macos – 如何以编程方式获取Finder中显示的“上次打开”日期

macos – 如何以编程方式获取Finder中显示的“上次打开”日期,第1张

概述我想在我的应用程序中显示“上次打开”日期,就像在Finder预览或信息面板中一样.但是我意识到这与我最后的访问日期不一样 NSDate* lastAccessDate = [fileUrl resourceValuesForKeys:@[NSURLContentAccessDateKey] error:NULL][NSURLContentAccessDateKey]; 或者 struct stat 我想在我的应用程序中显示“上次打开”日期,就像在Finder预览或信息面板中一样.但是我意识到这与我最后的访问日期不一样

NSDate* lastAccessDate = [fileUrl resourceValuesForKeys:@[NSURLContentAccessDateKey] error:NulL][NSURLContentAccessDateKey];

或者

struct stat buf;stat(curname,&buf);time_t lastAccessDate = buf.st_atimespec.tv_sec;

这些返回Unix上次访问时间,该时间也显示在终端中,用于ls -l
但是,Finder会显示一个不同的值,该值仅在用户打开文件时更改(例如,通过双击)

我阅读了帖子‘Get the real “last opened” date?’和‘“Last Opened” Date’,但这些都没有解决.他们推荐类似的东西

MDItemRef itemRef = MDItemCreateWithURL(NulL,(__brIDge CFURLRef)fileUrl);NSArray *attributenames = (__brIDge NSArray *)MDItemcopyAttributenames(itemRef);NSDictionary *attributes = (__brIDge NSDictionary *) MDItemcopyAttributes(itemRef,(__brIDge CFArrayRef) attributenames);CFDateRef lastUsedCfDate = MDItemcopyAttribute(itemRef,kMDItemLastUsedDate);NSDate* lastUsedDate = (__brIDge NSDate*) lastUsedCfDate;CFRelease(itemRef);

但是attributenames没有值kMDItemLastUsedDate.在我的例子中,该数组中只有24个值,但最后一个没有.所以lastUsedDate是零……

另外我想知道是否确实没有高级API来访问上次打开的日期.

解决方法 http://forums.macrumors.com/showthread.php?t=855913

引用chown33:

Extended attributes are completely different from Metadata. Xattrs are attached to the file,stored as part of the file-system. Metadata is extracted from the file,stored in the Metadata store (essentially,Spotlight’s database). Some xattrs are extracted and stored in the Metadata store,but they’re still two separate things.

The commands that operate on Metadata fit the ‘md*’ globbing pattern: mdfind,mdls,mdutil,etc.

You generally don’t get to update any of the Metadata values. This is by design,from what I can see by looking at the low-level API.

总结

以上是内存溢出为你收集整理的macos – 如何以编程方式获取Finder中显示的“上次打开”日期全部内容,希望文章能够帮你解决macos – 如何以编程方式获取Finder中显示的“上次打开”日期所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1009175.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存