在AppleScript中逐行迭代文件?

Wel*_*lls 7 applescript

我试图弄清楚如何在AppleScript中逐行迭代文件.类似于bash脚本,如下所示:

for LINE in $(cat file)
do
   echo ${LINE}
done
Run Code Online (Sandbox Code Playgroud)

有小费吗?谢谢!

kdm*_*ray 10

我不能因为写这篇文章而受到赞扬,我从MacRumors论坛的帖子回复了代码.

tell application "Finder"
  set Names to paragraphs of (read (choose file with prompt "Pick text file containing track names"))
  repeat with nextLine in Names
    if length of nextLine is greater than 0 then
      --Do something with the next name, which is stored in "nextLine"
    end if
  end repeat
end tell
Run Code Online (Sandbox Code Playgroud)

MacRumors论坛上的HexMonkey原始代码.

  • 没有必要告诉Finder做这些事情.您应该从Finder tell块中取出所有代码.Applescript可以自己处理代码,而Finder经常忙于处理其他任务,因此甚至可能会降低代码的速度. (4认同)