Applescript代码在High Sierra上工作,但在蒙特雷上不行
我想查看一个文件夹,以选择每个名称包含“ 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两个主要错误:
myFolder
是一个别名说明符。您可以添加文件夹
关键字,它是双重引用,deleteas as as as as as as as y/code>在第一行
OneFile
是Finder File File Specifier,您无法附加字符串返回
。也许将文件指定板静静地胁迫到塞拉利昂的字符串。如果要使用文件引用,则返回
语句无论如何都没有意义。另一个不好的做法是在被列举时修改数组
删除123
。创建一个额外的变量。并且重复循环也没有意义总是
true
。There are two major mistakes:
myFolder
is an alias specifier. You add thefolder
keyword which is a double reference, deleteas alias
in the first lineoneFile
is a Finder file specifier, you cannot append the stringreturn
. Maybe the file specifier is silently coerced to string in Sierra. If you want to use the file references then thereturn
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 alwaystrue
and even if you check the current item in the looponeFile
it's alwaystrue
.