AppleScript 从 TSV 文件中的特定列获取变量

AppleScript get variable from a specific column in a TSV file

我是 AppleScript 的新手,我需要您在以下方面提供帮助:

我有一个格式如下的 TSV 文件:

       [COLUMN A] [COLUMN B] [COLUMN C] [COLUMN D] (...)
[Line 1]Data      Data       Data       Data
[Line 2]Data      Data       Data       Data
(...)

我想为文件的每一行执行新的 Google 图片搜索。关键字将取自 A 列和 D 列,而不是 B 列或 C 列。

我设法创建了一个脚本来打开文件并执行搜索,所以我的问题是 "only" 能够使用一些特定的列,而不是全部(这就是我正在做的使用我当前的脚本)。

这是我的脚本:

set thetext to read (choose file) 
repeat with line_number from 1 to count of paragraphs in thetext 
    set line_text to paragraph line_number of thetext 

    tell application "Google Chrome" 
        activate
        tell front window to make new tab at after (get active tab) with properties {URL:"http://images.google.com/images?ie=ISO-8859-1&hl=en&btnG=Google+Search&q=" & line_text}
    end tell
end repeat

您将如何处理 "split the line"(脚本中的 line_text)并仅使用特定的列进行搜索?它是一个 TSV 文件,因此它在数据列之间使用表格。

谢谢:)

这就是 text item delimiters 的用途。您的 line_text 是一个形式为 "Data1\tData2\tData3\tData4" 的字符串,所以让我们以此为例:

set line_text to "Data1\tData2\tData3\tData4"
set the text item delimiters to "\t"
set theData to every text item of line_text

结果:

{"Data1", "Data2", "Data3", "Data4"}

现在,如果您想要该行的第四列数据,您只需要 item 4 of theData