代码之家  ›  专栏  ›  技术社区  ›  Daddy

AppleScript从HTTP服务器下载文件,改变URL?

  •  3
  • Daddy  · 技术社区  · 14 年前

    游戏设计师Bungie正在系统命名的文件和目录中为Halo-Reach托管大量png。即:

    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中单词的实例,然后将相关文件下载到目录?今天是我的生日(10月27日!因此二十七)如果这将工作,我会非常兴奋,如果有人能做到这一点!

    谢谢你的回答!

    1 回复  |  直到 14 年前
        1
  •  1
  •   Philip Regan    14 年前

    这是有效的:

    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