A similar script of mine has just broken with Monterey as well:
--Check if System Preferences already open?
--Don't want to quit it on exit if it's already running
set appName to "System Preferences"
if application appName is running then
set appRunning to true
else
set appRunning to false
end if
--Toggle Automatic Display Brightness
tell application "System Preferences"
set current pane to pane id "com.apple.preference.displays"
tell application "System Events"
tell process "System Preferences"
tell checkbox "Automatically adjust brightness" of tab group of window 1
click
--Display a matching notification
if value = {0} then
display notification "Automatic Brightness Disabled: Manual Override" with title "Manual Display Brightness"
end if
if value = {1} then
display notification "Automatic Brightness Enabled: Sensor Engaged" with title "Automatic Display Brightness"
end if
end tell
end tell
end tell
end tell
--Quit System Preferences if this script opened it up
if appRunning = false then
tell application "System Preferences" to quit
end if
This one executes with no errors reported, but does not click the button, and does not fire either notification.