Alice Meade Alice Meade - 23 days ago 8
AppleScript Question

getting last modified date for file in Applescript

I am trying to get the last modified date for a file in Applescript. I thought I had this working using

set thePath to (((path to documents folder) as text) & "speed.txt")

set modDate to modification date of file thePath

This seemed to return a valid value. But when I put this inside an On Idle piece of the code,
I get an

"can't get class <> of..." error

I saw somewhere else a suggestion to use:

set the modDate to (do shell script "mdls -name kMDItemLasUsedDate " & quoted form of the POSIX path of thePath)

But this returns Null.

Any ideas would be welcome.

Answer

You need to reference the file.

Try

set thePath to (((path to documents folder) as text) & "speed.txt")
tell application "System Events" to set modDate to modification date of file thePath

or

tell application "System Events" to set thePath to file (((path to documents folder) as text) & "speed.txt")
set modDate to modification date of thePath