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

在Applescript中,如何读取网站并将文本作为变量输出?,applescript,Applescript,在Applescript中,如何读取网站并将文本作为变量输出 我想从中读取“最新”的数字,然后使用该数字从中下载最新版本的Chromium。不是直接的Applescript方式,但这很有效 创建一个shell脚本进行下载,在$HOME/bin目录中显示chrome-download.sh: #!/bin/sh BUILD=`curl http://build.chromium.org/buildbot/snapshots/sub-rel-mac/LATEST` echo "Downloading

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


我想从中读取“最新”的数字,然后使用该数字从中下载最新版本的Chromium。

不是直接的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"
do shell脚本”/bin/bash/Users//bin/chrome download.sh“

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

不是直接的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"
do shell脚本”/bin/bash/Users//bin/chrome download.sh“

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

正如Glenn所说,只使用shell脚本并可能通过使用
do shell script
将其包装到AppleScript中要容易得多。如果您想在脚本中添加某种GUI,另一种选择是查看名为的程序


最后,如果您正在寻找一个已经实现了这一点的示例脚本,那么几天前Chromium Mac发布时,我制作了一个示例脚本:(源代码在GitHub上)。

正如Glenn所说,使用shell脚本并可能通过使用
do shell script
将其封装在AppleScript中要容易得多。如果您想在脚本中添加某种GUI,另一种选择是查看名为的程序


最后,如果您正在寻找一个已经实现了这一点的示例脚本,我在几天前Chromium Mac发布时制作了一个示例脚本:(来源于GitHub)。

一个更具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访问脚本和StandardAdditions字典中找到更多信息。(文件>打开字典)

一种更为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访问脚本和StandardAdditions字典中找到更多信息。(文件>打开字典)