Spelling and Grammar Window interferes with GUI scripting

I have a script that files emails and attachments as PDF’s where I tell it. This was put togther with a lot of help from this forum for which I am very grateful.

Have run tinto a small problem that cuases the script to hang. IF the “Spelling and Grammar” window is open the scrip hangs waiting for the next sheet. Thought I could run a command that found the dialog box and closed it before proceeding so I tried running this to see what is open.

tell application "System Events" to get the name of every window of every process

It returns amongst the other open windows the “Find” dialog window. Are the Spelling and Find windows somehow related?

Thanks

Peter

Curious.

Here, running 10.8.2 in French, I got :

with Spelling and Grammar open from Text Edit :

{{}, {}, {}, {}, {}, {}, {}, {“Mac4Ever”}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {“MacScripter / Post a reply”}, {}, {“Preferences”, “Bibliothèque”, “Bibliothèque”}, {“.GlobalPreferences.plist”}, {“Sans titre 2”, “Sans titre”, “a_library.applescript”, “Script d’un développeur non identifié”}, {}, {“Sans titre”}, {}, {“index Archives AppleScript Users.txt”, “Sans titre”}, {}, {}, {}, {}, {}, {}}

with Spelling and Grammar open from Script Editor :

{{}, {}, {}, {}, {}, {}, {}, {“Mac4Ever”}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {“MacScripter / Spelling and Grammar Window interferes with GUI scripting”}, {}, {“Preferences”, “Bibliothèque”, “Bibliothèque”}, {“.GlobalPreferences.plist”}, {“Orthographe et grammaire”, “Sans titre 2”, “Sans titre”, “a_library.applescript”, “Script d’un développeur non identifié”}, {}, {“Sans titre”}, {}, {}, {“Sans titre”}, {}, {}}

As you see, the window name appears only in the 2nd case.

I ran Accessibility Inspector while TextEdit was running.
When I put the cursor in the Spelling and Grammar window, Accessibility Inspector waited 30 seconds before being able to report infos related to the Spelling window.

Yvan KOENIG (VALLAURIS, France) dimanche 25 novembre 2012 11:11:34

In 10.6.8, and maybe in 10.8.2, the Spelling and Grammar window is a floating window which only exists (as far as System Events is concerned) while the process which owns it is frontmost.

Thank you both but not sure I have advanced much. I noticed that if the “Spelling and Grammar” window is open when I click on an email to select it then click on the script to run it the Spelling window goes away to be replaced by the “Find” window. What I need to do is close the window before the rest of the script runs if it is open. However as when this works I will be running the script from a a Hotkey not sure how to check for it.

Thanks again

Peter

The “Spelling and Grammar” window is a floating window open in (presumably) Mail. When you take the focus away from Mail to run the script, its floating window(s) aren’t displayed and don’t exist as far as GUI Scripting’s concerned. The “Find” window you’re seeing is possibly open in the application from which you’re running the script.

To close a floating window in Mail, bring Mail back to the front:

tell application "System Events"
	tell application process "Mail"
		set frontmost to true
		-- This code will need adjustment if it's possible that more than one floating window could be open in Mail.
		tell (first window whose subrole is "AXFloatingWindow")
			if (it exists) then click button 1
			repeat while (it exists)
				delay 0.2
			end repeat
		end tell
	end tell
end tell

Hello Nigel

What was puzzling me was mainly the fact that “Accessibility Monitor” required 30 seconds to be able to display infos related to the floating window when the cursor was in this one.

I’m now even more puzzled because during new tests made after reading your message, the infos surface instantaneously.

Yvan KOENIG (VALLAURIS, France) dimanche 25 novembre 2012 17:38:26

Hi

Just ran Nigel scrip after opening a mail message setup to reply and then brought up the spelling window and it worked, thanks very much.

I will now add that as a handler to my script immediately after calling mail and that should be the end of that problem.

Thanks again

Peter