System handling of UI Scripting click on menu extras is very slow

Originator:jalkut
Number:rdar://22990177 Date Originated:06-Oct-2015 10:17 AM
Status:Open Resolved:
Product:OS X Product Version:10.11
Classification:Performance Reproducible:Always
 
Summary:
Scripts that use GUI Scripting to automate selection of menu items hosted by SystemUIServer run dramatically slower on 10.11 than on 10.10. This seems to be rooted in an artificial delay experienced after "clicking" the status item to reveal its content. Although the clicked item's menu appears instantly, control is not given back to the script for several seconds.

This is a regression from 10.10 where the click is handled immediately and control given back to the script for further automation.

Steps to Reproduce:
1. Ensure the Text Input menu extra is enabled from Keyboard System Preferences -> Input Sources
2. Open attached SlowClickTest.scpt in Script Editor
3. Run the script.
4. Ensure GUI Scripting is allowed for Script Editor if necessary.
5. Run the script again.

Expected Results:
The script should run and in very short time click the Text Input menu and then click the "U.S." item.


Actual Results:
After clicking the text input menu to display the menu, there is a long delay of 5 seconds or more. Finally, control is given back to the script and the last click is able to proceed.

Run the same script on 10.10 to see it work instantly.

Note the delay is not tied to the Text Input menu in particular but there seems to be a delay in any clicking of any SystemUIServer hosted menu extra item.

The same delay is not imposed on clicks of other menu items, e.g. this simple script to quickly click the Apple menu and then select About This Mac:

tell application "System Events" to tell the front menu bar of process "Finder"
	tell menu bar item 1
		click
		tell menu item "About This Mac" of front menu
			click
		end tell
	end tell
end tell

Version:
10.11 (15A284)

Notes:


Configuration:


Attachments:
'SlowClickTest.scpt' was successfully uploaded.

Comments

Contents of the SlowClickTest script:

-- Example Script demonstrating the very slow response to "click" on the Text Input menu -- in OS X 10.11. Compare with 10.10 to see it behave instantly on 10.10 in contrast to -- very slow handling on 10.11.

tell application "System Events" to tell the front menu bar of process "SystemUIServer" -- Identify the text input menu extra menu log "Finding text input menu" set menu_extras to value of attribute "AXDescription" of menu bar items repeat with x from 1 to the length of menu_extras if item x of menu_extras is "text input" then exit repeat end repeat

-- Click an item by name
log "Clicking menu item"
tell menu bar item x
    click
    tell menu item "U.S." of front menu
        click
    end tell
end tell

end tell


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!