Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an XML file that has links to various .jpg I want to create an applescript that downloads a local copy of these. The idea is to also label them sequentially with a number say 001 to 030.

Every time i run the script i want the pictures to be overwritten with the new ones.

Here is the XML file I need to use:

Can anyone help?

share|improve this question
Have you actually written any script for us to look at? Is there a language you should be implementing this script in? – SoFLy Feb 5 '13 at 2:23

If a shell script solution is acceptable as well, try the following

for u in $(curl -s "$URL" |
           grep jpg | 
           sed -E 's/.*<profile_image_url>(.+)<\/profile_image_url>/\1/'); do
    curl -s "$u" -o $i.jpg
    (( i++ ))

This of course only works for this specific XML example and requires all files to be in jpg format.

share|improve this answer

Here is another approach:

-- Notice last "/" on path below
set downloadFolder to "/Users/squirrel/Desktop/testFolder/"

set myImages to every paragraph of (do shell script "curl | grep -o \\>.*jpg | sed 's/\\>//'")

repeat with i from 1 to count of myImages
    set fileName to do shell script "echo " & quoted form of (item i of myImages) & " | grep -o [^/]*$ | sed 's/\\.jpg/-" & addOs(i, 3) & ".jpg/'"
    do shell script "curl " & quoted form of (item i of myImages) & " -o " & quoted form of (downloadFolder & fileName as text)
end repeat

on addOs(myNumber, desiredDigits)
    set myNumber to myNumber as text
    set moreOs to desiredDigits - (myNumber's length)
    repeat moreOs times
        set myNumber to "0" & myNumber
    end repeat
    return myNumber
end addOs
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.