AppleScript and System Events "keystroke" function lead to incorrect casing when using uppercase letters

Number:rdar://29825727 Date Originated:29-Dec-2016 10:36 AM
Status:Closed Resolved:No
Product:macOS + SDK Product Version:macOS Sierra 10.12.2 (16C67)
Classification:Serious Bug Reproducible:Always
Something not on this list

This is an "us, too" report for rdar://29182929 where the keystroke function is incorrectly casing of output to uppercase based on uppercase and other sentinel characters. We've also identified a work-around that we haven't seen reported, described in Additional Notes.

Steps to Reproduce:
1. Open Script Editor
2. Either open the attached sample script or paste this:
tell application "Terminal"
	tell application "System Events" to keystroke "This is a test"
end tell
3. Watch the output in

Expected Results:
The script should properly print each entered character in the correct casing.

Actual Results:
The casing is different from what was entered and differs with almost every run.

macOS Sierra 10.12.2 (16C67)

This is our work-around, forcing an adjustment to shift after using keystroke to emit each character individually:

tell application "Terminal"
	tell application "System Events"
		set outputString to ""
		set len to length of outputString
		repeat with i from 1 to len
			set x to character i of outputString
			keystroke x
			key up {shift}
		end repeat
	end tell
end tell

I should note that the problem appears to remain in 10.12.3 Beta 2.

The output is occasionally correct, but the frequency varies quite a bit.

'AdjustKeystroke.scpt' was successfully uploaded.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!