Ich möchte eine AppleScript-Anwendung erstellen, die beim Ausführen Folgendes tut:
Öffnen Sie Safari und navigieren Sie zu einer bestimmten URL oder einer zeilengetrennten Datei oder CSV. Dies ist nicht erforderlich, würde aber das Erstellen mehrerer Screenshots verschiedener Seiten viel schneller machen.
Ändern Sie die Größe des Safari-Fensters auf eine von mehreren Größen
Machen Sie einen Screenshot des Safari-Fensters, wobei der Dateiname die URL zusammen mit der Bildschirmgröße ist
Ich habe nur eine Teillösung bekommen , die bis auf ein paar Kleinigkeiten funktioniert.
Erstens können Sie die URL nicht im Dateinamen speichern (aufgrund von Schrägstrichen und Sonderzeichen), sodass Sie den Website-Namen angeben müssen.
Aber noch wichtiger ist, dass der CSV-Import bisher nicht implementiert ist. Ist CSV wirklich eine zwingende Voraussetzung, oder könnten Sie die Liste der URLs in einem anderen Format erhalten? Wenn nicht, aktualisieren Sie bitte Ihre Frage mit beispielhaften Zeilen Ihrer CSV-Datei. Ich werde daran arbeiten und meine Antwort so schnell wie möglich aktualisieren.
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
Es ist besser zu prüfen, ob die Seite fertig geladen ist, bevor Sie einen Screenshot machen. Nehmen Sie Asmus 'ursprünglichen Teilantwortcode in etwa so wie ...
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
...übernimmt es.
Michael
Asmus