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.