Keystroke and 10.12.2

Hello

Since the delivery of 10.12.2, the script used to insert my signature plays the fool.
After every character defined as uppercase ones, one or several other characters defined as lowercase are inserted as uppercase.
Is it an already reported behavior ?
The active part of the script is :

set leMessage to "Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France)"


tell application "System Events" to tell process theApp
	set frontmost to true
	keystroke return & leMessage & return
end tell

where theApp is the process active when the script is executed.
If the target process is Safari, the result is :

[format]YVan KOENIG RUNNiNg SIErra 10.12.2 iN FRENch (VALLAURIS. FRance)[/format]

If the target process is Firefox, the result is:
[format]YVAN KOENIG running SIErra 10.12.2 in FrENch (VALLAURIS. FRAnce)[/format]

If the target process is TextEdit, the result is even worse:

[format]YVAN KOENIG RuNNiNg SIERra 10.12.2 In FRENCh 5VALLAURIS. FRANce)[/format]

As you may see, the problem strikes also upon the opening paren which, on french keyboard is the lowercase counterpart of the character 5 [ ⇧) → 5 ]

I was able to retrieve a correct behavior using :

set leMessage to "Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France)"

set leMessage to return & leMessage & return
set messageChars to text items of leMessage
tell application "System Events" to tell process theApp
	set frontmost to true
	repeat with aChar in messageChars
		keystroke aChar
		delay 0.002 # I don't understand why it was missing, probably pasted from a wrong file
	end repeat
end tell

It seems that the keystroke tool type the characters too fast so that the uppercase mode remains active when the wanted lowercase chars are sent.
The signature displayed below was inserted with the edited code.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mercredi 14 décembre 2016 12:17:30

Problem confirmed by a friend running also 10.12.2.
It strike also in 10.12.13.

Reported as :
Report # 29683268, Under 10.12.2 (and 10.12.3) AppleScript keystroke command fails

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 15 décembre 2016 16:24:33

Yvan,

I’ve had the same issue with 10.12.2 and keystroke. Putting the code in a loop didn’t work for me, I had to also add a delay in between keystrokes for it to function properly.

Cheers,
Nick

You’re right nickorr.
I posted the wrong code.
The correct one sent to Apple contains a delay 0.002 instruction.
I will edit the original message.

Would be fine if many users send a report to Apple so that they take care of the problem.
When I filed my report I had only tested on the system used in French.
At last, I decided to boot in English and saw that the problem strike also in this configuration so I completed my report accordingly.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) vendredi 16 décembre 2016 11:43:20

just my 2 cents on this experience.

what i tested.
WORKED

  • created a new account with a new username. ran the script.

DID NOT WORK

  • thought it was localized to my account
    ---- removed entire library folder > restarted
    ---- deleted my account created a new account with the same username
    ---- reinstalled OS worked for a second then still the issue

Haven’t tried

  • wipe and resintall > with same user account

On my side I also have the problem on the external HD where I made a clean install of 10.12 before installing 10.12.3.
As my tests upon beta versions are related to localisation oddities, I doubt that something clobbered my user account on this disk.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mercredi 4 janvier 2017 20:58:25

So it looks like it’s definitely the OS 10.12 iteration of the os that results in these issues. So won’t clean and reinstall. The odd thing. it didn’t work under “accountA” but it did in “accountB” and it didn’t work in “accountA1” adding the “1” in “accountA” still didn’t work. Very strange but definitely a fix needed from apple’s side.

so i guess wipe and clean isn’t going to fix it.

You may file a bug report.
I sent one as you may read in message #2

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 5 janvier 2017 11:38:40

Also, sent a bug report. Made it into a sub-routine for those who need to use it repeatedly


set leMessage to "Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France)"
set AppName to "Terminal"  -- change to app process 

my charKeystroke(leMessage, AppName)

on charKeystroke(leMessage, AppName)
	set leMessage to return & leMessage & return
	set messageChars to text items of leMessage
	tell application "System Events" to tell process AppName
		activate
		set frontmost to true
		repeat with aChar in messageChars
			keystroke aChar
			delay 0.002 # I don't understand why it was missing, probably pasted from a wrong file
		end repeat
	end tell
end charKeystroke

I would use a slightly enhanced version.

set leMessage to "Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France)"

tell application id "com.apple.TextEdit"
	activate
	--set AppName to its name
	if not (exists window 1) then make new document
	repeat until exists window 1
		delay 0.2
	end repeat
end tell

my charKeystroke(leMessage)

on charKeystroke(leMessage)
	set leMessage to return & leMessage & return
	set messageChars to text items of leMessage
	
	tell application "System Events"
		set frontmostProcess to first process where it is frontmost -- this will be the script process
		if name of frontmostProcess is in {"Script Editor", "AppleScript Editor", "Script Debugger"} then
			set visible of frontmostProcess to false -- hide the script process
			repeat while (frontmostProcess is frontmost) -- wait until the script is hidden
				delay 0.1
			end repeat
			set theProcess to name of first process where it is frontmost -- get name of frontmost process (ignoring the script process)
			set frontmost of frontmostProcess to true -- unhide the script process
		else
			set theProcess to name of frontmostProcess
		end if
		tell process theProcess
			set frontmost to true
			repeat with aChar in messageChars
				keystroke aChar
				delay 0.002
			end repeat
		end tell
	end tell
end charKeystroke

This way I may run it from the Editor.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 5 janvier 2017 22:12:30