views:

37

answers:

1

I've never messed with AppleScript so this is only a concept to me. Can this work?

Bungie, the game designer, is hosting a ton of PNGs for Halo Reach in systematically named files and directories. IE:

http://www.bungie.net/images/reachstats/commendations/onyx/onyx_large_precision_multiplayer.png

Change two instances of the same word, and you generate another version of the image. Change "onyx" to "iron", "bronze", "silver" or "gold" and you get a corresponding image, like so:

http://www.bungie.net/images/reachstats/commendations/gold/gold_large_precision_multiplayer.png

Would an AppleScript be able to take an input URL, find and change the instances of the words in the URL, and then download the associated file to a directory? Today is my birthday (Oct 27th! hence the XXVII) and if this will work I would be super excited if someone could make this!

Thanks for all of your kind answers!

+1  A: 

This works:

set the destination_file to ((path to desktop as string) & "picture.jpg") as file specification
set thisImageSRC to "http://www.bungie.net/images/reachstats/commendations/gold/gold_large_precision_multiplayer.png"
tell application "URL Access Scripting"
    download thisImageSRC to destination_file replacing yes
end tell

String manipulation is done completely with changing Applescript's text item delimiters. So to get the components of the URL into a list, you need to do the following:

set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set theUrlComponents to (every text item of theURL) as list
set AppleScript's text item delimiters to oldDelims

Add salt to taste, but I agree with the first commenter that there are better languages to do this. Applescript would be my last choice here.

Philip Regan
AppleScript editor highlights the first line "file specification" and gives me an error message. Am I supposed to be changing that to something else?
JustinXXVII
URL Access Scripting is just a front end for the `curl` command. You should just be able to delete it and have it still work.
Philip Regan