Applescript代码在High Sierra上工作,但在蒙特雷上不行

发布于 2025-02-10 13:34:17 字数 651 浏览 2 评论 0原文

我想查看一个文件夹,以选择每个名称包含“ ABC”的文件。

这是我的applescript代码:

set myFolder to (((path to library folder from user domain) as string) & "FOLDER") as alias

tell application "Finder"

    set deleted123 to every file of folder myFolder whose name contains "abc"
        repeat with oneFile in deleted123
        if exists (deleted123) then set end of deleted123 to oneFile & return
        --Do something
        end repeat
    
    if deleted123 ≠ {} then
        --Do something else with the selected.
    end if
end tell

该代码在High Sierra上完美无缺,即它发现了所有名称包含“ ABC”的文件,但它不在蒙特雷上。

问题是什么?如何改进此代码?

帮助高度赞赏。

I want to look into a folder to select every file whose name contains "abc".

Here is my AppleScript code:

set myFolder to (((path to library folder from user domain) as string) & "FOLDER") as alias

tell application "Finder"

    set deleted123 to every file of folder myFolder whose name contains "abc"
        repeat with oneFile in deleted123
        if exists (deleted123) then set end of deleted123 to oneFile & return
        --Do something
        end repeat
    
    if deleted123 ≠ {} then
        --Do something else with the selected.
    end if
end tell

The code works flawlessly on High Sierra, i.e., it finds out all the files whose names contain "abc", but it doesn't on Monterey.

What is the problem? How can this piece of code be improved?

Help highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

束缚m 2025-02-17 13:34:17

有两个主要错误:

  1. myFolder是一个别名说明符。您可以添加文件夹关键字,它是双重引用,delete as as as as as as as as y/code>在第一行
  2. OneFile是Finder File File Specifier,您无法附加字符串返回。也许将文件指定板静静地胁迫到塞拉利昂的字符串。如果要使用文件引用,则返回语句无论如何都没有意义。

另一个不好的做法是在被列举时修改数组删除123。创建一个额外的变量。

并且重复循环也没有意义总是true

There are two major mistakes:

  1. myFolder is an alias specifier. You add the folder keyword which is a double reference, delete as alias in the first line
  2. oneFile is a Finder file specifier, you cannot append the string return. Maybe the file specifier is silently coerced to string in Sierra. If you want to use the file references then the return statement makes no sense anyway.

Another bad practice is to modify the array deleted123 while being enumerated. Create an extra variable.

And the repeat loop makes no sense either because exists (deleted123) is always true and even if you check the current item in the loop oneFile it's always true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文