在applescript中,如何在Web上返回文件的内容?

时间:2011-02-25 15:01:10

标签: file applescript

在AppleScript中,如何在网络上返回文件的内容?所以,如果我做了foo.com/untitled.txt,它会给我该文件的内容。

2 个答案:

答案 0 :(得分:2)

我建议使用do shell script来调用命令行实用程序curl来完成这项工作,如下所示:

set theText to do shell script "/usr/bin/curl http://foo.com/test.txt"

答案 1 :(得分:0)

on curl(URI)
    tell me to do shell script "/usr/bin/curl " & quoted form of URI
end curl

或另一种方式:

on temporaryFile()
    tell me to POSIX file (do shell script "/usr/bin/mktemp " & quoted form of (POSIX path of (path to temporary items from user domain) & (do shell script "/usr/bin/basename " & quoted form of POSIX path of (path to me) & " '.app'") & "XXXXXXXX")) as alias
end temporaryFile

on fetchPage(URI)
    set temporaryFile0 to my temporaryFile()
    tell application "URL Access Scripting"
        --progress,form data,directory listing,download directory,authentication
        download URI to temporaryFile0 replacing yes
    end tell
    set fileReference to open for access temporaryFile0
    try
        set returnValue to read fileReference
    on error number -39
        set returnValue to ""
    end try
    close access fileReference
    tell application "Finder" to delete temporaryFile0
    returnValue
end fetchPage