代码之家  ›  专栏  ›  技术社区  ›  Konrad

向AppleScript脚本授予权限

  •  0
  • Konrad  · 技术社区  · 5 年前

    我有一个简单的应用程序脚本,它应该删除 下载 文件夹,但末尾传递的选定文件夹列表除外。

    tell application "Finder"
        delete (every item of "Downloads" of folder currentUser of folder "Users" of startup disk whose name is not in {"PreciousFolder"})
    end tell
    

    保存时,AppleScript返回以下错误:

    errormessage

    0 回复  |  直到 5 年前
        1
  •  1
  •   vadian    5 年前

    您将删除文本字符串的每一项 "Downloads" 这毫无意义。添加 folder 说明符

    tell application "Finder"
        delete (every item of folder "Downloads" of folder currentUser of folder "Users" of startup disk whose name is not in {"PreciousFolder"})
    end tell
    

    或者更短

    tell application "Finder"
        delete (every item of (path to downloads folder) whose name is not in {"PreciousFolder"})
    end tell