所以我有一个文件夹,其中有许多文件的数量定期变化,我需要使用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
,因为选择文件夹只导致在一个系统事件告诉块内使用时,一个无尽的运行循环。
"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)