Strange scripting bug: Testers wanted


I use AppleScript for some tasks to test an application. Now I found a strange issue which I was able to reproduce with this small script in “Script”:

tell application "TextEdit" activate try get document 1 on error make new document end try repeat 10 times tell application "System Events" to keystroke "This is just a small test" & return end repeat end tell

It should just write 10 times the line “This is just a small test”.

On my macOS 10.12.2 machine I get this strange result:

[quote]THIS Is juST a small test
This is just a small test
This is just a small test
This is juST a small test
This is just a small test
This IS jUst a sMall test
This is juST A SMALL test[/quote]

On another mac using the same OS version it woks fine. So I want to ask if someone else get this strange result to get a clue what’s the reason of this issue.



Are you touching the shift key at all while the script is running?
The leading T is always capital, never inverse, so I think sending the keystrokes might be getting mixed with your shift key.

Works fine for me, OS X 10.10.5 with TextEdit 1.10. I tried a few times hitting the shift key in the middle of the event, and only during one test did it shift during the write, but not back and forth as your test. I had half in lower case, then the rest in uppercase.

Of curse not. I get always random results…

During my tests, I found that the event happens too quickly to respond to the keyboard to produce those results. Even pressing the shift key rapidly, video game style, didn’t result in any difference. Only once did I happen to hit the key at apparently the exact microsecond to have the case change during the event. I had to change the repeat to 100 times, and with hitting the key as fast as I could, there were only 7-8 times during the 100 lines where the case changed. Never did I have a result where the case changed after a few characters. It would be at least 12-13 lines for either upper or lower case characters. And, I started pressing the shift key rapidly before I even hit the run key.

It becomes even stranger. Using the string “this is just a small test” (note the lower caps “t”) everything is Ok. Even a 1000 times loop shows always the correct output.
By using an upper case “T” I get the wrong result, so “This is just a small test” gives

[quote]THis is just a small test
THIS is just a small test
THIS IS Just a small test
THIS is just a small test
THis is just a small test
THIS IS Just a small test
This is just a small test
This IS Just a SMaLl test
THIS Is just a small test
This is just a small test[/quote]

Another test using another user case character:
Using “this is Just a small test” (upper case “J”) gives

[quote]this is JUSt a small test
this is JUST A SMall test
this is Just a small test
this is JUst a small test
this is JuST a SMALL Test
this is JUSt a sMall test
this is JuST A Small test
this is Just a small test
this is Just a small test
this is JuSt a small test[/quote]

So it seems that there is something buggy when an upper case character is used…

What that’s weird. The system must be simulating a shift key press to get the capital letter then?
Maybe Siri isn’t moving her fingers fast enough?
That’s so odd.

Faulty keyboard?

Have you tried switching keyboards between the 2 test machines?

Edit: Not sure how a faulty keyboard could affect the results only if there is a capital letter in the string, and work properly with only lower case letters, but it could be worth a quick test. I don’t know if the ‘system events’ accesses the keyboard or not for this action.

Nope. I removed my keyboard (USB cable, no Bluetooth) and I got the same wrong output.

Here’s a Radar for the bug

Unfortunately I don’t think it contains any info you haven’t already discovered.

Many thanks Will. This helps.
I was already wondering why it did not work on my Mac but on another Mac. Now I can look for a workaround.