在 Applescript 我如何阅读网站,并将文本作为变量输出?
问问题
3800 次
3 回答
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 脚本。
于 2009-05-26T01:55:10.353 回答
2
正如 Glenn 所说,使用 shell 脚本并可能通过使用do shell script
. 如果您想要脚本的各种 GUI,另一种选择是查看一个名为Platypus的程序。
最后,如果您正在寻找一个已经这样做的示例脚本,我在几天前宣布 Chromium Mac 时做了一个: http: //chealion.ca/2009/05/chromium-build-bot-updater-script/(来源在 GitHub)。
于 2009-05-26T06:02:34.610 回答
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 访问脚本和 StandardAdditions 字典中找到更多信息。(文件 > 打开字典)
于 2011-07-16T03:06:06.137 回答