I am running last Monterey on an intel Mac and AppleScript can not reliably send keystrokes any more. Is there any way to choose a new desktop with AppleScript without sending keystrokes? I was using code like:
if (desk = 1) then
tell application “System Events” to key code 18 using control down
else if (desk = 2) then
tell application "System Events" to key code 19 using control down
else if (desk = 3) then
tell application "System Events" to key code 20 using control down
Try maybe nesting the keystroke
inside a tell process "Finder"
block. If my memory serves me correctly that turns out to work better.
Otherwise, give cliclick a try. Use do shell script
to invoke it and chain some actions together to achieve a key down on ctrl
, arrow key press, and key up on ctrl
.
The problem is Monterey operating system when running on an Intel machine has a problem with Apple script controlling the computer with key strokes. Even when all the permissions are given, it’ll work for a little while and then quit; maybe come back spontaneously and quit again. Running any script that wants key strokes causes an error message when it fails. What I was hoping for was a way to choose desktops without key strokes.