Missing text in status bar of Safari

Hi!

In a bigger script I have a small section that checks if a web page is fully loaded in Safari.
The script checks the text in Safaris status bar for certain conditions.

When i included this section (found at this site) a few years ago, the text i needed to check was located in “name of static text 1 of group 1 of window 1” - but in 10.7 this has changed to group 2. Safari also displayed the text in the status bar at the bottom of the browser window.

Anyway: This section of script is no longer stable - and I’m trying to find out why.

Can anyone lead me in the right direction?
The script is modified to work with both english and norwegian system.

on checkLoading()
repeat
delay 1
tell application “System Events” to tell application process “Safari”
if (name of static text 1 of group 2 of window 1 as text) begins with “Kontakter” or ¬
(name of static text 1 of group 2 of window 1 as text) begins with “Contacting” or ¬
(name of static text 1 of group 2 of window 1 as text) begins with “Laster” or ¬
(name of static text 1 of group 2 of window 1 as text) begins with “Loading” then
else
exit repeat
end if
end tell
end repeat
end checkLoading

Hi,

in 10.8 the group has been even changed to group 3.
To retrieve the text of the status line use value rather than name

Try this


property timeoutValue : 10 -- seconds
property safariGroup : 1

on checkLoading() -- returns true on success and false on timeout
	set safariGroup to checkSystemVersion()
	set timeoutCounter to timeoutValue * 2
	repeat while timeoutCounter > 0 and isLoading()
		delay 0.5
		set timeoutCounter to timeoutCounter - 1
	end repeat
	return (timeoutCounter > 0)
end checkLoading

on isLoading()
	set returnValue to ""
	try
		tell application "System Events"
			tell process "Safari"
				tell window 1
					set returnValue to value of static text 1 of group safariGroup
				end tell
			end tell
		end tell
	end try
	return (returnValue begins with "Kontakter" or returnValue begins with "Contacting" or ¬
		returnValue begins with "Laster" or returnValue begins with "Loading")
end isLoading

on checkSystemVersion()
	set systemVersion to ((system attribute "sysv") mod 4096 div 16)
	if systemVersion < 7 then
		return 1
	else if systemVersion = 7 then
		return 2
	else
		return 3
	end if
end checkSystemVersion

You might have an easier time checking if the “Stop” menu item is enabled. If it is, the page is loading, if not, the page is done.

tell application "System Events" to tell application process "Safari" to get enabled of menu item "Stop" of menu 1 of menu bar item "View" of menu bar 1

There’s also JavaScript:

set timer to 10

delay 1
set timer to timer - 1
tell application "Safari"
	repeat until (((do JavaScript "document.readyState" in front document) is "complete") or (timer = 0))
		delay 0.5
		set timer to timer - 0.5
	end repeat
end tell

Sorry for late answer to this.
I went back to my old mac for a while so the problem dissapeared, but now I’m back on track, and now I need to solve it.

Thanks for the suggestions. I will try them to see if it makes my script run properly.

.inge.

Model: MacBook Pro
Browser: Firefox 22.0
Operating System: Mac OS X (10.7)