将列表设置为 AppleScript 中的 shell 脚本输出
我有一个输出文件名的 shell 脚本(每行一个)。我想将该输出放入 AppleScript 中的列表中。
我该怎么做?
关于如何将这些文件名字符串转换为文件对象的奖励积分。
编辑:
尝试此操作时:
set theFiles to {}
repeat with i from 1 to count of filenames
set end of theFiles to (POSIX file (item i of filenames))
end repeat
我得到以下信息:
error "Finder got an error: Can’t get POSIX file \"/path/to/file\"." number -1728 from file "Macintosh HD:path:to:file"
编辑2:
事实证明查找器不知道“tell”语句开始后创建的文件。如何更新它或让它知道新文件?
EDIT-3:
这有效(注意添加“我的”):
set theFiles to {}
repeat with i from 1 to count of filenames
set end of theFiles to (my POSIX file (item i of filenames))
end repeat
I have a shell script that outputs filenames (one per line). I want to put that output into a list in AppleScript.
How can I do this?
Bonus points for how to then turn those filename strings into file objects.
EDIT:
When trying this:
set theFiles to {}
repeat with i from 1 to count of filenames
set end of theFiles to (POSIX file (item i of filenames))
end repeat
I get this:
error "Finder got an error: Can’t get POSIX file \"/path/to/file\"." number -1728 from file "Macintosh HD:path:to:file"
EDIT-2:
Turns out finder isn't aware of a file that gets created after the "tell" statement starts. How do I update it or make it aware of the new file?
EDIT-3:
This worked (note the addition of "my"):
set theFiles to {}
repeat with i from 1 to count of filenames
set end of theFiles to (my POSIX file (item i of filenames))
end repeat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您有一个列表时,您可以使用重复循环来迭代该列表并对列表中的项目执行某些操作。例如,如果您想要文件对象的列表,您可以这样做。
当然,这样做没有多大意义,因为一旦您在列表中拥有文件对象,那么您将需要重复该列表以对这些对象执行某些操作...因此您将重复列表2 次,1 次可能就足够了。所以我会做这样的事情......
When you have a list, you use a repeat loop to iterate over the list and do something with the items in the list. For example if you wanted a list of the file objects you could do this.
Of course it doesn't make much sense to do this because once you have the file objects in a list then you'll need to repeat over that list to do something with those objects... thus you'll be repeating over a list 2 times when 1 time would probably suffice. So I would do something like this instead...