在AppleScript中获取文件的上次修改日期

问题描述 投票:2回答:1

我正在尝试在AppleScript中获取文件的最后修改日期。我以为我有这个工作使用:

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

这似乎返回一个有效的值,但当我把它放在代码的on idle片段时,我得到一个:

“无法获得......的类<”错误

我在其他地方看到了一个建议:

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

但这会返回null。关于如何获得修改日期的任何想法?

file applescript last-modified
1个回答
4
投票

您需要引用该文件。

尝试

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

要么

tell application "System Events" to set thePath to file (((path to documents folder) as text) & "speed.txt")
set modDate to modification date of thePath
© www.soinside.com 2019 - 2024. All rights reserved.