unable to tell "System Events" in Monterey

I am trying to fetch the active app using Apple Script.

This code worked before updating to Monterey. Now I am getting time out every time I run this snippet.

on getCurrentApp()
	try

		with timeout of 5 seconds
			tell application "System Events"
				set activeApp to name of first application process whose frontmost is true
				say activeApp
			end tell

		end timeout

	on error

		say "Timeout"

	end try

end getCurrentApp

off-topic: Is there any way to identify if my system is locked or trigger a script when "Lock screen" event occurs.

How are you testing this? I tried this myself and it seem to work:

  1. I fired up the latest macOS 12.0 beta (b4).

  2. I ran Script Editor.

  3. I pasted your script into the new script window.

  4. I then added a call to getCurrentScript.

  5. I ran it.

It worked just fine for me, speaking “Script Editor” (which is the frontmost app, obviously).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

unable to tell "System Events" in Monterey
 
 
Q