I want iterate through all windows of Safari application
to find all main windows like this:
but it throws exception:
I’m pretty confused, as I iterate through all windows :
I see all windows have either document:missing value
or document:document “MacScripter / AppleScript | OS X”
it confuses me even more as iteration like this
runs like a charm…
How can I find list of windows with non-empty document element by a single iteration? Is it possible?
Model: Mac Book Pro 2009
Browser: Safari 533.17.8
Operating System: Mac OS X (10.6)
I have found workaround for this confusion by checking window names, but it look ugly as well as check through ‘System event’ application.
here is quote from AppleScriptLanguageGuide:
from which I deduce that my attempt to check for ‘document’ element against ‘missing value’ is pretty correct.
But alas! I it is not. Now after finding workaround I want to find theoretical explanation why my code doesn’t work.
Any clue?
tell application "System Events"
tell process "Safari"
get windows whose value of attribute "AXRoleDescription" is "standard window"
end tell
end tell
Is OK for systems used in English but the value of “AXRoleDescription” is localized…
So, for others it would be safer to use :
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
get windows whose value of attribute "AXSubrole" is "AXStandardWindow"
end tell
end tell
or maybe better :
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
get windows whose subrole is "AXStandardWindow"
end tell
end tell
strange enough - I cannot find any reference to that ‘empty’ state in AppleScript language guide.
Is there any way to check if variable is “empty” besides try/catch?
Actually I get ‘variable is not defined’ when I try access not defined variable.
It is understandable.
But in case of Safari windows when I print all properties of all items of ‘windows’ list - EACH of them has ‘document’ property!!! (which is either ‘missing value’ or ‘some document’)