2010-10-27 92 views
3

我從來沒有搞砸AppleScript,所以這只是一個概念給我。這可以工作嗎?AppleScript從HTTP服務器下載文件,改變URL?

Bungie,遊戲設計師,將在系統命名的文件和目錄中託管大量的Halo Reach PNG。 IE:同一個詞的

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

更改兩個實例,你生成圖像的另一個版本。更改「縞瑪瑙」到「鐵」,「青銅」,「白銀」或「黃金」,你會得到相應的圖像,像這樣:

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

會一個AppleScript能夠利用輸入URL,找到並更改URL中單詞的實例,然後將關聯的文件下載到目錄中?今天是我的生日(十月二十七日!因此XXVII),如果這將起作用,如果有人能做到這一點,我會非常興奮!

感謝您的所有答案!

+0

AppleScript是* so * last millenium。必須有更好的方法來做到這一點。我當然忘記了大約10年前我對AppleScript的所有知識,並且我不願意回想起它...... – 2010-10-27 13:00:46

+0

由於您在Mac上,我可能會使用wget使用shell腳本來執行此操作。 – 2010-10-27 13:01:50

+0

那好吧! – Justin 2010-10-27 13:02:43

回答

1

這工作:

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 

字符串操作與改變的AppleScript的文本項分隔符完全做到。因此,要獲得該URL的組件集成到一個列表,你需要做到以下幾點:

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 

加入鹽調味,但我第一個評論者,有更好的語言來做到這一點達成一致。 AppleScript是我最後的選擇。

+0

AppleScript編輯器突出顯示了第一行「文件規範」並給出了一條錯誤消息。我應該改變它到別的東西嗎? – Justin 2010-10-28 21:21:11

+0

URL訪問腳本只是'curl'命令的前端。您應該能夠刪除它並使其仍然有效。 – 2010-10-29 14:16:04