开发者

In applescript, how can I return the contents of a file on the web?

In applescript, how can I return the contents of a开发者_Go百科 file on the web? So if I did foo.com/untitled.txt, it would give me the contents of that file.


I would suggest using do shell script to call the command line utility curl to do the job, like so:

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


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

Or another way:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜