将file.txt中字符串的单词存储到变量AppleScript中

将file.txt中字符串的单词存储到变量AppleScript中,applescript,automator,Applescript,Automator,我有一个file.txt,它由一些字符串组成,每个字符串的结构如下: word1 word2 word3 我想写一个脚本,它允许我找到以“word1”开头的字符串,并将“word2”和“word3”的内容分成两个变量 像这样的 set searchTerm to "foo" set variable1 to "" set variable2 to "" set theText to paragraphs of (read (choose file)) repeat with aLine i

我有一个file.txt,它由一些字符串组成,每个字符串的结构如下:

 word1 word2 word3
我想写一个脚本,它允许我找到以“word1”开头的字符串,并将“word2”和“word3”的内容分成两个变量

像这样的

set searchTerm to "foo"
set variable1 to ""
set variable2 to ""

set theText to paragraphs of (read (choose file))
repeat with aLine in theText

    set theWords to words of aLine
    if item 1 of theWords is searchTerm and ((count theWords) > 3) then
        set variable1 to item 2 of theWords
        set variable2 to item 3 of theWords
        exit repeat
    end if
end repeat
执行shell脚本“var1=$(grep”字符串搜索“file.txt | cut-d”“-f3);var2=$(grep”字符串搜索“file.txt | cut-d”“-f5)”