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

发布于 2024-10-19 03:34:35 字数 75 浏览 4 评论 0原文

在applescript中,如何返回网络上文件的内容?因此,如果我执行 foo.com/untitled.txt,它会给我该文件的内容。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠佳期 2024-10-26 03:34:35

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

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

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"
执着的年纪 2024-10-26 03:34:35
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文