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?
Yes. There is a UNIX command called
kMDItemLastUsedDatethat returns the date the target item was last used.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
datebefore it, you’ll get a syntax error.Here is the revised script: