AppleScript to download files from an HTTP server, with a URL change?

I have never encountered AppleScript, so this is just a concept for me. Could this work?

Bungie, a game developer, places a ton of PNG 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 will create a different version of the image. Change “onyx” to “iron”, “bronze”, “silver” or “gold” and you will get the corresponding image, for example:

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

Can AppleScript accept an input URL, find and modify word instances in a URL, and then upload the linked file to a directory? Today is my birthday (October 27th! Therefore XXVII), and if it works, I would be thrilled if someone could do it!

Thanks for all your kind answers!

+3
source share
1 answer

It 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 processing is performed entirely with the change of Applescript text separators. To get the components of the URL in the list, you need to do the following:

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

Add salt to taste, but I agree with the first commentator that there are better languages ​​for this. Applescript will be my last choice here.

+1
source

Source: https://habr.com/ru/post/1771718/


All Articles