Reputation: 496
I have a list of movie titles stored in a variable movie_titles
in AppleScript.
{"Beautiful Girl 2014
The Aerialist 2020
Yvonne Orji Momma I Made It 2020
Dead Stop 2011
"}
I need to run a command for each title in that list. Open a URL where each title of the list movie_titles
is a part of that url. The result being a tab for each item in the list opened in my default browser.
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
That works for a list of one but it adds each line of a list of more than one into the URL. I realize that I need a second variable that grabs each line in succession and adds it to each repeat but I am not sure how to add this to the repeat statement.
I think I couldn't find a good example because I am not sure which search words/phrase to use. If you can provide an answer and a short explanation I would appreciate.
Upvotes: 0
Views: 2125
Reputation: 3422
You need to break up the input string at the line endings in order to create the list items. AppleScript text objects have a paragraphs
element that uses return, linefeed, or return/linefeed as delimiters, so you can do something like:
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
Upvotes: 1