0

Currently I have a process that downloads image URL from a website. Then I filter out URLs I don't need and am left with a list of good image URLs. I want to reformat these URLs by adding [IMG] before and [/IMG] tags after so these images are ready to post on sites that require these tags. So far, I'm not finding a good way to accomplish this.

Any ideas or suggestions?

  • Trivially accomplished using an old-fashioned Bash, Python, or Ruby script (all of which are installed on OS X out of the box). Does it have to be in AppleScript or Automator? – dodgethesteamroller Dec 21 '15 at 22:37
  • No, any process that will loop through all the URLs from the prior step and process them until none are left would be just fine. – MattSh Dec 22 '15 at 15:35
1

Assuming I'm understanding your question correctly, a simple program in any scripting language will do this in just a few lines of code. Perl, Python, and Ruby are preinstalled on OS X; I'll give an example in Perl. Just run this at the command prompt in a Terminal window.

Given that the filenames you want to process are listed, one filename per line, in a textfile called infile.txt:

perl -pe 's/(.*)/<img>$1<\/img>/;' < infile.txt > outfile.html

Explanation: Calling the perl executable with the -e flag means "run the code in quotes following"; the -p flag means "for every line on standard input, run the program (meaning the code in quotes in this case) on that line and then print the line"; and the actual program in single quotes merely adds the <img></img> tags at the beginning and end of whatever text is in that line of the file. The < and > operators indicate input and output to the given filenames.

0

It's pretty simple to make a concatenation with Apple Script

set i to 0
repeat
    set a to "[IMG]"
    set b to myUrlArray[i]
    set c to "[/IMG]"
    set myConcatUrl to a & b & c
    display dialog myConcatUrl
    if myUrlArray length == i then exit repeat
end repeat

or you can make a repeat while (i <= myUrlArray length)

However I never make an AppleScript before... Make a full AppleScript tutorial and write your script by your own. If you have some difficulties with the code, you can go on StackOverflow and if you have some problems with Apple built-ins, behaviours... come here and post an another question.

AskDifferent is not a code-writing service.

http://macosxautomation.com/applescript/firsttutorial/index.html

http://stackoverflow.com

Google Search

  • But it processes the first one, then that's it. There has to be some type of looping process so that it processes all 5 or all 50 URLs. There is a looping process in Automator, but that sends it back to step one, so that won't work. It has to read the first one, do the concatenation process, write out, get the next one, etc, until none are left to process. – MattSh Dec 22 '15 at 15:34
  • @MattSh I have edited my answer. – StrawHara Dec 22 '15 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .