I need a piece of code to check to see if a webpage is loaded. If the page is loaded, the script must finish (so I can have it handed off to Quickkeys to do GUI scripting). If the page isn’t loaded, I need the script to keep checking.
I found this section of code from Apple Script for Dummies
tell application "Safari"
activate
make new document
set the URL of document 1 to "http://www.macnn.com/"
set loaded to false
repeat until loaded
try
set the_text to the source of document 1
set start_info to the offset of "Apple Stock Quote" in the_text
if start_info > 0 then
set loaded to true
end if
on error e
delay 2
end try
end repeat
end tell
activate
set end_info to start_info + 40
set the_info to characters start_info through end_info of the_text as string
set end_info to the offset of return in the_info
set the_info to characters 1 through end_info of the_info as string
display dialog the_info
I tried to extract just the part I needed, and came up with the following, **Warning!, this script causes my script editor to freeze up!! Becareful before running
tell application "Safari"
activate
make new document
set the URL of document 1 to "http://www.macnn.com/"
set loaded to false
repeat until loaded
try
set the_text to the source of document 1
if start_text > 0 then
set loaded to true
end if
end try
end repeat
end tell
Here it is outside of the fancy click thing, tell application “Safari”
activate
make new document
set the URL of document 1 to “http://www.macnn.com/”
set loaded to false
repeat until loaded
try
set the_text to the source of document 1
if start_text > 0 then
set loaded to true
end if
end try
end repeat
end tell
Anyone have any ideas on how I can get this script to simply check if the page is loaded, and if so, end, and if not, then keep checking?
Thanks!
Tyler