Sysem Events' Windows.... Dictionary wrong, or can't I read it?

In the System Events dictionary, there is a window object with properties like visible, position, bounds, resizable.

This script, however, fails:


tell application "System Events"
    repeat with theApp in application processes
        repeat with theWin in windows of theApp
            get visible of theWin
        end repeat
    end repeat
end tell

The error is:

get visible of item 1 of every window of item 9 of every application process "System Events got an error: Can't make visible of item 1 of every window of item 9 of every application process into type reference."
The dictionary says that application processes have windows, and that windows have visible properties.

Is it just this particular window that doesn’t have a visible property? I checked the dictionary of that particular application, and its window object has a visible property, too.

In addition to all this, the script editor is rewriting my code. if I write:

	get resizable of someWindow

and press compile, the code becomes:

	get presentation size of someWindow

No amount of rewriting “resizable” remedies this. The word is always replaced.

Model: Macbook Pro
AppleScript: 1.10.7
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.7) Gecko/20060911 Camino/1.0.3
Operating System: Mac OS X (10.4)

Not every application that is visible will have open windows, but this returns those that are.


set W to {}
tell application "System Events"
	set P to application processes where it is visible
	repeat with theApp in P
		set end of W to {name of theApp, name of windows of theApp}
	end repeat
end tell

Why is it that my code does not work, though? I used visible because it was a simple example.

An application has windows which have properties named “visible”, “bounds”, “position”, etc.

If I have a window object in variable theWin, should I not be able to somehow reference its properties? “name of theWin” “if theWin is visible”, “theWin’s position”, etc. (These are English language examples, I don’t know if any of them other than “[property] of [object]” are valid applescript syntax)

Does applescript not allow me to access the properties of an object, or do I have to select a set of objects from a list whose properties match a criteria, as you have described above? Is there no way to access the visible property of an window object, perhaps assign it to a variable? (set wVis to visible of theWin)

Why does my code above fail?

Why does the following code fail?:


set W to {}
tell application "System Events"
	set P to application processes where it is visible
	repeat with theApp in P
		set end of W to {name of theApp, name of windows of theApp, bounds of windows of theApp}
	end repeat
	
end tell

All I’ve done is extended your syntax to another property of the window object, namely “bounds”. This property is listed in the “System Events” dictionary as being a property that windows have, just like “name” is a property that windows have.

Am I reading the dictionary incorrectly? Where can I find the property list of a window of an application of application processes?

I hear you and sympathize after spending 20 minutes trying to extract window dimensions inside a System Events loop. Easy once you know the names of the applications by asking each directly. Hopefully, someone more skilled than I am will tell us both.

I wish…:slight_smile:

However, how about this? I just threw in a bit from another script - http://bbs.applescript.net/viewtopic.php?id=18703 - It would be better if the window bounds were listed after each window, which shouldn’t be too hard to change.


set W to {}
tell application "System Events"
	set P to application processes where it is visible
	repeat with theApp in P
		set end of W to {name of theApp, name of windows of theApp}
		tell application process theApp
			repeat with theWindow in every window of theApp
				set {{p1, p2}, {s1, s2}} to theWindow's {position, size}
				set windowBounds to {p1, p2, p1 + s1, p2 + s2}
				tell application process theApp
					set end of W to windowBounds
				end tell
			end repeat
		end tell
	end repeat
	
end tell
return W

Ahh, that breaks the icejam, CJ; A slight improvement puts window titles with sizes.


set W to {}
tell application "System Events"
	set P to application processes where it is visible
	repeat with theApp in P
		set end of W to {name of theApp}
		tell theApp
			repeat with theWindow in every window of theApp
				set {WT, {p1, p2}, {s1, s2}} to theWindow's {title, position, size}
				set windowBounds to {WT, p1, p2, p1 + s1, p2 + s2}
				tell application process theApp to set end of last item of W to windowBounds
			end repeat
		end tell
	end repeat
end tell
return W

Yeah, I’ve been working with the size property, and I have my script working, but it doesn’t answer my fundamental questions:

Why is it that in the System Events dictionary, there is no size property, but we’re able to access it? Meanwhile, we’re not able to access the properties that are there?

Example: here.