【问题标题】:Running into problem when using choose folder in AppleScript在 AppleScript 中使用选择文件夹时遇到问题
【发布时间】:2021-10-05 04:54:18
【问题描述】:

所以我有一个包含许多文件的文件夹,这些文件的数量会定期更改,我需要使用 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

【问题讨论】:

  • 系统事件 也可以处理它(尽管您可能希望将计数限制为可见文件) - 只是不要在应用程序告诉语句中使用 choose folder 对话框(养成的好习惯)。
  • @user3439894 你想把它写成答案吗?

标签: applescript finder


【解决方案1】:

如果您只想获取所选文件夹文件计数,而不是子文件夹子文件夹中的文件,然后使用:

tell application "Finder" to return count files of container (choose folder)

如果您想要 文件夹items 的完整 count,请使用:

tell application "Finder" to return count items of entire contents of container (choose folder)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    • 2013-10-04
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多