Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 正在获取AppleScript中文件的上次修改日期_File_Applescript_Last Modified - Fatal编程技术网

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

File 正在获取AppleScript中文件的上次修改日期,file,applescript,last-modified,File,Applescript,Last Modified,我正在尝试获取AppleScript中文件的最后修改日期。我想我是通过以下方式工作的: set thePath to (((path to documents folder) as text) & "speed.txt") set modDate to modification date of file thePath 这似乎返回了一个有效值,但当我把它放在空闲的代码段中时,我得到一个: “无法获取…的类”错误 我在其他地方看到了一个建议: set the modDate to (do

我正在尝试获取AppleScript中文件的最后修改日期。我想我是通过以下方式工作的:

set thePath to (((path to documents folder) as text) & "speed.txt")
set modDate to modification date of file thePath
这似乎返回了一个有效值,但当我把它放在空闲的
代码段中时,我得到一个:

“无法获取…的类”错误

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

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

但这将返回
null
。关于如何获得修改日期,您有什么想法吗?

您需要参考该文件

试一试


它必须是applescript吗?您可以使用stat filenameFYI轻松实现这一点:对于您的do shell脚本命令,有一个“kMDItemContentModificationDate”可以工作。我建议的唯一调整是告诉应用程序系统事件,而不是查找器。一般来说,在可能的情况下,最好避免使用Finder。既然Finder和系统事件都有“modification date”属性,我会使用后者。另外,我很惊讶您的第二个示例能够工作,因为“modification date”不是applescript知道的属性。查找程序和系统事件都知道该属性,因此实际上您应该告诉其中一个应用程序执行该命令。我确实看到,当您使用其中一个应用程序创建文件引用时,在文件引用的末尾,它包括“of application Finder”。。。我猜这就是为什么“修改日期”调用在应用程序块之外工作的原因。你有不同的解释吗?嗨,雷格斯。系统事件更快,也接受posix路径,因此我将更新答案。(我有一个填充Finder的脚本调试器扩展,我很懒。)我发现一旦你在Finder或SE中引用了一个文件,你就可以在以后将它从一个tell块中排除。有趣的帖子。我注意到脚本返回的字符串如下:date“date”,2015年8月12日,星期三14:13:33“我假设这是特定于语言/地区的,那么如何将其转换为已知格式以便进行解析?
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