如何解决在 AppleScript 中使用选择文件夹时遇到问题
所以我有一个文件夹,里面有很多文件,这些文件的数量经常变化,我需要使用 AppleScript 来计算它们。一开始我有一个这样的脚本:
tell application "Finder" to return count of (every file of (choose folder))
后来,在研究的过程中,我发现了这样的事情:
tell application "Finder" to return count files of (choose folder)
然而,两者似乎都不起作用。我也不能使用 System Events
,因为在 System Events-tell 块中使用时,选择文件夹只会导致无限的运行循环。
我得到的错误是:
"Finder got an error: Expected a reference." number -1727
解决方法
如果您只想获取所选文件夹中文件的计数,而不是子文件夹或子文件夹中的文件,然后使用:
tell application "Finder" to return count files of container (choose folder)
如果您想要文件夹中项目的完整计数,请使用:
tell application "Finder" to return count items of entire contents of container (choose folder)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。