Answers:
我只得到了一个部分解决方案,除了一些小问题之外。
首先,您不能将URL存储在文件名中(由于斜杠和特殊字符),因此您需要指定网站名称。
但更重要的是,到目前为止还没有实现CSV导入。CSV真的是一个很难的要求,或者你能获得不同格式的URL列表吗?如果没有,请使用CSV文件的示例行更新您的问题。我会继续努力并尽快更新我的答案。
on open_url(theUrl, theUrlName, x0, y0, xSize, ySize)
tell application "Safari"
open location theUrl
activate
set bounds of window 1 to {x0, y0, xSize, ySize}
set windowID to id of window 1
set the_state to missing value
repeat until the_state is "complete"
set the_state to (do JavaScript "document.readyState" in document 1)
delay 0.3
end repeat
set theFolder to POSIX path of (path to desktop as string)
set shellCommand to "/usr/sbin/screencapture -l " & windowID & " " & quoted form of (theFolder & "Screen Shot " & theUrlName & " " & xSize & "x" & ySize & ".png")
do shell script shellCommand
end tell
end open_url
set resolutionList to {{640, 480}, {1024, 768}}
set siteList to {{"http://www.apple.com", "Apple"}, {"http://www.google.com", "Google"}}
repeat with resolution in resolutionList
set xSize to item 1 of resolution
set ySize to item 2 of resolution
repeat with theSite in siteList
set theUrl to item 1 of theSite
set theUrlName to item 2 of theSite
open_url(theUrl, theUrlName, 0, 0, xSize, ySize)
end repeat
end repeat
在进行屏幕截图之前,最好检查页面是否已完成加载。以Asmus的原始部分答案代码为基础......
delay 10
tell application "Safari"
do JavaScript "document.readyState == 'complete'" in window 1's current tab
end tell
set loaded to result
if loaded is true then
set shellCommand to "/usr/sbin/screencapture -l " & windowID & " " & quoted form of (theFolder & "Screen Shot " & theUrlName & " " & xSize & "x" & ySize & ".png")
do shell script shellCommand
end if
...将负责它。