Question

I'm 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

and 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 on how I can get the modified date?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top