Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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: http://tweetriver.com/hud_ro/steer_filtered.xml?include_entities=1

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

2 Answers 2

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

#!/bin/bash
URL='http://tweetriver.com/hud_ro/steer_filtered.xml?include_entities=1'
i=0
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++ ))
done

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 http://tweetriver.com/hud_ro/steer_filtered.xml?include_entities=1 | 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

 
discard

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.