列表中每个项目的 Applescript 重复命令。作为变量添加到命令的每一行
Applescript repeat command for each item in list. Each line added to command as variable
我在 AppleScript 的变量 movie_titles
中存储了一个电影标题列表。
{"Beautiful Girl 2014
The Aerialist 2020
Yvonne Orji Momma I Made It 2020
Dead Stop 2011
"}
我需要为该列表中的每个标题运行一个命令。打开 URL,其中列表 movie_titles
的每个标题都是 url 的一部分。结果是在我的默认浏览器中打开的列表中的每个项目都有一个选项卡。
repeat with i in movie_titles
do shell script "open 'http://www.imdb.com/find?ref_=nv_sr_fn&q= " & movie_titles & "&s=tt&ttype=ft'"
end repeat
这适用于一个列表,但它会将多个列表的每一行添加到 URL 中。我意识到我需要第二个变量来连续获取每一行并将其添加到每个重复项中,但我不确定如何将其添加到重复语句中。
我想我找不到一个很好的例子,因为我不确定要使用哪个搜索words/phrase。如果您能提供答案和简短的解释,我将不胜感激。
您需要在行尾拆分输入字符串才能创建列表项。 AppleScript 文本对象有一个 paragraphs
元素,它使用 return、换行符或 return/linefeed 作为分隔符,因此您可以执行以下操作:
set movieTitles to "Beautiful Girl 2014
The Aerialist 2020
Yvonne Orji Momma I Made It 2020
Dead Stop 2011"
repeat with anItem in paragraphs of movieTitles
if contents of anItem is not "" then -- skip blank lines
do shell script "open 'http://www.imdb.com/find?ref_=nv_sr_fn&q=" & anItem & "&s=tt&ttype=ft'"
end if
end repeat
我在 AppleScript 的变量 movie_titles
中存储了一个电影标题列表。
{"Beautiful Girl 2014
The Aerialist 2020
Yvonne Orji Momma I Made It 2020
Dead Stop 2011
"}
我需要为该列表中的每个标题运行一个命令。打开 URL,其中列表 movie_titles
的每个标题都是 url 的一部分。结果是在我的默认浏览器中打开的列表中的每个项目都有一个选项卡。
repeat with i in movie_titles
do shell script "open 'http://www.imdb.com/find?ref_=nv_sr_fn&q= " & movie_titles & "&s=tt&ttype=ft'"
end repeat
这适用于一个列表,但它会将多个列表的每一行添加到 URL 中。我意识到我需要第二个变量来连续获取每一行并将其添加到每个重复项中,但我不确定如何将其添加到重复语句中。
我想我找不到一个很好的例子,因为我不确定要使用哪个搜索words/phrase。如果您能提供答案和简短的解释,我将不胜感激。
您需要在行尾拆分输入字符串才能创建列表项。 AppleScript 文本对象有一个 paragraphs
元素,它使用 return、换行符或 return/linefeed 作为分隔符,因此您可以执行以下操作:
set movieTitles to "Beautiful Girl 2014
The Aerialist 2020
Yvonne Orji Momma I Made It 2020
Dead Stop 2011"
repeat with anItem in paragraphs of movieTitles
if contents of anItem is not "" then -- skip blank lines
do shell script "open 'http://www.imdb.com/find?ref_=nv_sr_fn&q=" & anItem & "&s=tt&ttype=ft'"
end if
end repeat