在Applescript中如何阅读网站,并将文本输出为变量?

时间:2009-05-26 01:27:56

标签: applescript

在Applescript中如何阅读网站,并将文本作为变量输出?

我想阅读here中的“最新”号码,然后使用该号码从here下载最新版本的Chromium。

3 个答案:

答案 0 :(得分:2)

不是直接的Applescript方式,但这很有效。

创建一个shell脚本来执行下载,比如说$ HOME / bin目录中的chrome-download.sh:

#!/bin/sh
BUILD=`curl http://build.chromium.org/buildbot/snapshots/sub-rel-mac/LATEST`
echo "Downloading build "$BUILD
curl http://build.chromium.org/buildbot/snapshots/sub-rel-mac/$BUILD/chrome-mac.zip -o $HOME/chrome-mac-$BUILD.zip

在一行中从Applescript(或Automator)运行它:

do shell script "/bin/bash /Users/<your username>/bin/chrome-download.sh"

下载的文件位于$ HOME目录中。 bash脚本也可以在Linux或Cygwin中运行。当然,您也可以直接运行bash脚本。

答案 1 :(得分:2)

正如Glenn所说,只使用shell脚本并使用do shell script将其包装在AppleScript中要容易得多。如果您想要对脚本进行分类的GUI,另一种选择是查看名为Platypus的程序。

最后,如果您正在寻找已经执行此操作的示例脚本,我会在几天后宣布Chromium Mac时发布一个:http://chealion.ca/2009/05/chromium-build-bot-updater-script/(GitHub上的源代码)。

答案 2 :(得分:1)

AppleScript原生的方式更多:

set filePath to (path to temporary items folder as string) & "file.html"

tell application "URL Access Scripting"
    download "http://www.apple.com/sitemap/" to file filePath replacing yes
end tell

--read file into a variable
try
    open for access (file filePath)
    set fileData to (read file filePath)
    close access (file filePath)
on error errMsg number errNum
    try
        close access file filePath
    end try
    error errMsg number errNum
end try

您可以在URL Access Scripting和StandardAdditions词典中找到更多信息。 (文件&gt;打开词典)