-- check_Safari_page_loaded handler
on check_Safari_page_loaded(wait_secs)
set loaded to false
set cnt to 0
repeat until loaded
set cnt to cnt + 1
delay 0.5
tell application "System Events" to ¬
tell process "Safari"
set x to (value of static text 1 of window 1 as text)
set y to ""
if exists group 1 of window 1 then
if exists (static text 1 of group 1 of window 1) then set y to (value of static text 1 of group 1 of window 1 as text)
end if
if y = "" then
set w_Name to x
else
set w_Name to y
end if
set loading to false
if (w_Name begins with "Contacting") then set loading to true
if (w_Name begins with "Loading") then set loading to true
if (w_Name begins with "Untitled") then set loading to true
if loading and not (cnt > (wait_secs * 2)) then
set loaded to false
else
set loaded to true
exit repeat
end if
end tell -- process Safari
end repeat
if cnt > wait_secs * 2 then set loaded to false
return loaded
end check_Safari_page_loaded
-- check_Safari_page_loaded handler