2011-07-14 7 views
1

は、私はそうのようなテキストファイルがあるとのAppleScriptリストは

0123:それ のような特定することはできませんので

item list 1={apples, pencils, juice} 
item list 2={apricots, John Doe, the string system is amazing} 

ただし、テキストファイルには、以上の6行と行の異なるテキストが含まれています

set line1 of myfile to item 1 of mylist 
set line2 of myfile to item 2 of mylist 
set line3 of myfile to item 3 of mylist 

set line4 of myfile to item 1 of mySecondlist 
set line5 of myfile to item 2 of mySecondlist 
set line6 of myfile to item 3 of mySecondlist 

答えて

4

これを試してください。コードは自明である必要がありますが、助けが必要な場合は質問してください。

-- get the text from the file 
set theFile to choose file 
set theText to read theFile 

-- turn the text into a list so we can loop over it 
set theTextList to paragraphs of theText 

-- put every 3 items into a list and add it to the finalList variable 
set listCount to count of theTextList 
set finalList to {} 
repeat with i from 1 to listCount by 3 
    if (i + 2) is not greater than listCount then 
     set end of finalList to items i thru (i + 2) of theTextList 
    else 
     set end of finalList to items i thru listCount of theTextList 
    end if 
end repeat 

-- show the list of lists result 
return finalList 

あなたのファイルはあなたが示した値が含まれていた場合は、ここでの結果だ...

{{"apples", "pencils", "juice"}, {"apricots", "John Doe", "the string system is amazing"}} 
+0

あなたは完璧に動作しますありがとう! – evdude100