在AppleScript中逐行迭代文件?

时间:2010-07-22 05:19:23

标签: applescript

我试图弄清楚如何在AppleScript中逐行遍历文件。类似于bash脚本,如:

for LINE in $(cat file)
do
   echo ${LINE}
done

任何提示?谢谢!

1 个答案:

答案 0 :(得分:9)

我不能因为写这篇文章而受到赞扬,我从MacRumors论坛的response to a post中解除了代码。

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

MacRumors论坛上HexMonkey的原始代码。