Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating through file line by line in AppleScript?

Tags:

applescript

I am trying to figure out how to iterate through a file line by line in AppleScript. Similar to a bash script like so:

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

Any tips? Thanks!

like image 430
Wells Avatar asked Jul 22 '10 05:07

Wells


1 Answers

I can't take credit for writing this, I lifted the code from a response to a post in the MacRumors forums.

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

Original code credit to HexMonkey on the MacRumors forum.

like image 121
kdmurray Avatar answered Oct 06 '22 00:10

kdmurray