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

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

问题描述

我可以使用
set modDate to the modification date of theFile as string获取文件的最后修改日期,并且
set modDate to the creation date of theFile as string获取创建文件的日期.

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.

是否有类似last opened date的文件来获取文件的上次打开日期?

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天全站免登陆