Applescript 获取文件的最后打开日期 [英] Applescript get last opened date of file

查看:19
本文介绍了Applescript 获取文件的最后打开日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用
将modDate设置为文件的修改日期为字符串获取文件的最后修改日期,以及
将 modDate 设置为文件的创建日期作为字符串 以获取文件的创建日期.

I can use
set modDate to the modification date of theFile as string to get the last modified date of a file, and
set modDate to the creation date of theFile as string to get the date when the file was created.

是否有类似上次打开日期之类的东西来获取文件上次打开的日期?

Is there anything like last opened date to get the date when the file was last opened?

推荐答案

是的.有一个名为 kMDItemLastUsedDate 的 UNIX 命令,它返回目标项目上次使用的日期.

Yes. There is a UNIX command called kMDItemLastUsedDate that returns the date the target item was last used.

set the Last_opened_date to (do shell script "mdls -name kMDItemLastUsedDate " & quoted form of the POSIX path of theFile)

但是,此命令不会返回文字日期对象.相反,它以 ISO 8601:2004 格式 (YYYY-MM-DD HH:MM:SS) 返回一个日期对象,如果您尝试将 date 放在它之前,您将收到语法错误.

However, this command doesn't return a literal date object. Instead, it returns a date object in ISO 8601:2004 format (YYYY-MM-DD HH:MM:SS) which, if you try to put date before it, you'll get a syntax error.

这是修改后的脚本:

property months : {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

set the Last_opened_date to date convert_date(do shell script "mdls -name kMDItemLastUsedDate " & quoted form of the POSIX path of theFile)

on convert_date(passed_data)
    set prevTIDs to AppleScript's text item delimiters
    set AppleScript's text item delimiters to space
    set the ISO_date to the first text item of (passed_data as string)
    set AppleScript's text item delimiters to "-"
    set the date_parts to every text item of the ISO_date
    set the_year to the first text item of the date_parts
    set the_month to the second text item of the date_parts
    set the_day to the third text item of the date_parts
    set AppleScript's text item delimiters to space
    set the time_string to the second text item of (passed_data as string)
    set AppleScript's text item delimiters to prevTIDs
    return item (the_month as integer) of months & the_day & ", " & the_year & space & the time_string
end convert_date

这篇关于Applescript 获取文件的最后打开日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆