file - 在 AppleScript 中获取文件的最后修改日期

标签 file applescript last-modified

我正在尝试获取 AppleScript 中文件的最后修改日期。我以为我可以使用以下方法进行此操作:

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

这似乎返回了一个有效值,但是当我将其放入代码的空闲片段中时,我得到一个:

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

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

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

但这会返回null。关于如何获取修改日期有什么想法吗?

最佳答案

您需要引用该文件。

尝试

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

关于file - 在 AppleScript 中获取文件的最后修改日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19058156/

相关文章:

c 从文件中读取并获取两个字符之间的字符串

java - 如何用JAVA从txt文件中删除最后一行brak行?

java - 从文本文件中获取所有单词(Java)

macos - 在 OS X 上以管理员权限运行脚本

file - 如何在 Lua 中获取最后修改的时间戳

linux - 检查文件的所有行是否包含在另一个文件中

if-statement - 苹果脚本 "if contain"

macos - 如何查看 AppleScript “whose” 子句的内部以优化脚本对象说明符的解析?

loops - 基于 'Last Modified Date' 遍历文件夹中的所有文件

java - Java中的类可以确定它是否被修改了吗?