Script Editor Window Count

I’ve run into a small oddity. I open, say, 5 Script Editor windows and run the following script (by way of a keyboard shortcut):

tell application "Script Editor"
	display dialog "Window count: " & (count windows)
	close front window
end tell

Each time I run the script, one Script Editor window is closed but the window count remains at 5. If I do this with Safari rather than Script Editor, the script runs as expected and the window count is reduced by one each time the script is run. Anyone know why this happens? Thanks.

First of all you want to count all windows (plural)

I regard this as a bug. The windows seem to be hidden rather than closed, in terms of Objective-C orderOut: is called rather than close:

Thanks for the quick response. It’s good to know that I wasn’t missing something, and saves me some time. I’ve edited my original post and changed window to windows.

I did some google research on this and, FWIW, found a workaround that does the job in my script.

tell application "Script Editor"
		set windowCount to count (windows whose its document is not missing value)
	end tell

Hi.

If that does what you want, you may like:

tell application "Script Editor"
	set windowCount to (count documents)
end tell

Thanks Nigel. That works great and is much cleaner.