Apple script stopped working - "invalid index"

Hi there, I've created an Automator app running an Apple script to toggle a setting within the "systems preferences". I'm on German systems settings, so I hope you can make any sense out of the below... The intention is to toggle a setting within "Desktop & Dock" off and on again (i.e., just toggle the blue switch left and right in one go). I've attached screenshots to make clear what I mean.

I've been running the following Apple Script (for only a few weeks so far), and it worked perfectly fine until just recently:

on run {}

	repeat 2 times

		tell application "System Settings" to activate

			tell application "System Events"

				tell process "System Settings"

					click menu item "Schreibtisch & Dock" of menu "Darstellung" of menu bar 1

					delay 2

					tell window "Schreibtisch & Dock"

						click checkbox "Beim Programmwechsel Space auswählen, der geöffnete Fenster des Programms enthält" of group 9 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1

				end tell

			end tell

		end tell

	end repeat

end run

Now, since a few days, it keeps throwing an error message as follows:

"System Events" has received an error: "group 1 of window "Desktop & Dock" of process "System Settings"" cannot be read. Invalid index.

I'm not sure whether I've made an update of the MacOS in the meantime or what the reason could be. As mentioned, I'm not using the script for too much time, only a few weeks so far (mid-February).

My MacOS version: Sonoma 14.3.1 Macbook Pro 16" 2021 (Apple M1 Pro)

Unfortunately, my research did not point me into the right direction, I couldn't find an answer as to what exactly I'd need to change. Would much appreciate if anyone can help me set the correct index, or how to otherwise correct the script. Thanks a lot! S.

Apple script stopped working - "invalid index"
 
 
Q