在AppleScript中,如何在网络上返回文件的内容?所以,如果我做了foo.com/untitled.txt,它会给我该文件的内容。
答案 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