I have a large list of urls (urls.txt) \n separated, all valid RFC https urls in the usual format of https://example.com/path/path/path/file.jpg
All urls seem to be TLS/SSL
All urls seem to be jpg or gif file
All urls have manually been tested to work in Safari.
I want to read in the url's, loop through them, assign it to a variable as it passes through the loop, then I was thinking about using a heretic to shove in some applescript to run the open
( I am on mac OS X obviously :) ) command, which seems to nicely default url's to my default browser and also given a window with content in it, given my Safari preferences, a new tab will be fired open. So open
as a raw command does just what I want.
For some reason, the second I step outside of bash into the heredoc, things get messy and stop working. Applescript is a strange little cousin of that really strange kid in school.
Here is what I have been trying:
#!/bin/bash
echo -e "Fire open a new tab for each url on a line in a file.\n"
urls=$(cat urls.txt)
for i in $urls; do
echo "Opening URL item: $i"
#heredocs are nice
/usr/bin/osascript << EOF
set the_url to quoted form of $i
/usr/bin/open -a "/Applications/Safari.app" "$the_url"
EOF
done
exit 0
Here is a small snip of the error output that is sent back to the shell: $./go Fire open a new tab for each url on a line in a file.
Opening URL item: https://dl.dropboxusercontent.com/u/340087/drops/12.22.14/bbq-galore-and-more-59-082636.jpg 30:36: syntax error: A “:” can’t go after this identifier. (-2740) Opening URL item: https://dl.dropboxusercontent.com/u/340087/drops/12.22.14/card-88-082636.jpg 30:36: syntax error: A “:” can’t go after this identifier. (-2740) Opening URL item: https://dl.dropboxusercontent.com/u/340087/drops/12.22.14/catalog-c2-082636.jpg 30:36: syntax error: A “:” can’t go after this identifier. (-2740) Opening URL item: https://dl.dropboxusercontent.com/u/340087/drops/12.22.14/chris-360overlibrary-e9-082636.gif 30:36: syntax error: A “:” can’t go after this identifier. (-2740)
The colon can't go afer... error I am guessing is the colon in the url, since there aren't any others in the code that could cause the error in that location. I know there has to be a way to make it work, and I suspect it has to do with quoting. Perhaps I ned to add open Safari.app quoted form of $i or something like that.
Thank you for any help. Hopefully I can add to the top of the script echo "About to open $( wc -l urls.txt ) new tabs in Safari, are you ready?