Anyone else getting this bug?

I develop extensions for the Raycast app. And in many cases I need to simulate writing keystrokes automatically. For this I use often use AppleScript.

An example is pasting a command to be ran into a terminal automatically.

I am experiencing a weird bug where the keystroke command of tell application “System Events” is always capitalising letters.

I assume this is bug and not a feature i just havent noticed. Chatgpt had no idea so I i figured you guys are my best bet.

Anyone seen this same behavior?

Hi @emiara. Welcome to MacScripter.

I’m not seeing that on my system. Does the process for running the script involve holding Shift key down? Or is the Caps Lock on?

Hello @Nigel_Garvey!
The process for running the script does not involve holding Shift key.

For testing purposes I am running the code by pressing the run button in the standard AppleScript editor.

It happens seemingly for any text input I try. Turning on caps lock(which would normally inverse the use of the shift key) does nothing.

I have tested changing the input language of the keyboard.

This has worked as expected in the past. Turning off and on the computer did nothing either.

Hi @emiara.

The only other possibility that comes to mind is that System Events has a couple of ‘key’ commands which are no longer published in its dictionary because of the problems they can cause, but which still appear to work. They are key down and key up. If key down is used with shift, the shift key remains effectively pressed until the corresponding key up is issued or some kind of restart occurs.

tell application "System Events"
	key down shift
	keystroke "hello"
	key up shift
end tell

If the key up isn’t issued for some reason — say, a run time error before it’s reached or the key up command not being in the code — it can cause havoc with the use of the keyboard until it’s corrected! Do any of your scripts contain uncancelled key down shift commands?

Interestingly, fooling around with this in Ventura, another way to cancel the effect with shift appears to be to transition from upper to lower case in the input text sequence:

tell application "System Events"
	key down shift
	keystroke "hello world"
	keystroke "Hello world"
	key up shift
end tell
1 Like

Just as an additional data point, I do not have this issue on my Sequoia computer. Also, turning on the caps-lock key results in both hello-world strings being capitalized. With caps-lock off:

Thanks everyone for the help!

In the end running the code:

Seemes to have fixed the issue. My code runs as expected now:

Indeed the problem can be reproduced by running:

tell application "System Events"
	key down shift
end tell

No idea how my os got to that key down shift state in the first place. But I am happy to have found a solution.

Thanks alot @Nigel_Garvey for your insight.