AppleScript 中的条件是目录不包含扩展名递归则退出应用程序

AppleScript 中的条件是目录不包含扩展名递归则退出应用程序

这似乎可行。唯一的问题是它不是递归的。

property Location : alias "Macintosh HD:Location"
tell application "System Events" to files of Location whose name extension = "ext"
if the result = {} then tell application "Example" to quit

答案1

你可以使用 Finder 获取全部内容:

set f to POSIX file "/Users/username/folder" as alias
tell application "Finder"
    files of entire contents of f where name extension is "torrent"
end tell

如果文件夹中有很多文件,使用查找可能会更快:

do shell script "find ~/folder -name \\*.torrent" is not ""

答案2

尝试:

set downloadsPath to (path to downloads folder)
tell application "System Events" to files of downloadsPath whose name extension = "torrent"
if the result ≠ {} then tell application "Transmission" to activate

相关内容