Applescript whose expression

Greetings!

please, help. my mind is blowing up.

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)

Hi,

the value of an non existing document is actually not missing value, it’s empty (nil).

You can gather standard windows of applications with System Events


tell application "System Events"
	tell process "Safari"
		get windows whose value of attribute "AXRoleDescription" is "standard window"
	end tell
end tell

Stefan,

thank you for the reply!

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?

as the quote says missing value is a constant aka “something”.
But there is also the state “empty” which means just “nothing”.

If you try to assign an empty value to a variable you will get an “the variable is not defined” error
after a “get [variable]” line.

Unfortunately there is no common rule when a value is missing value or empty.

Hello

Stephan’s


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

Yvan KOENIG (VALLAURIS, France) mardi 24 août 2010 23:26:05

Yvan - thanks for remark about localization!

Stefan,

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’)

Can you explain it?