Automate open iPad as screen (sidecar) if there are no other screens detected

I also found this AppleScript here in the Forum (Link) from @Max_Megalon, but this code worked just once here (and opened AppleMusic instead), I restarted BTT but it never run again. :frowning:

for a german system use : "Kontrollzentrum"

tell application "System Events"

tell its application process "Kontrollzentrum"
	
	tell its menu bar 1
		-- click on and open Control Center drop down
		tell (UI elements whose description is "Kontrollzentrum")
			click
		end tell
	end tell
	
	
	-- interact with Control Center window
	tell its window "Kontrollzentrum"
		delay 0.5
		-- click screen mirroring button
		set screenMirroringButton to button 2 of group 1
		-- click screenMirroringButton click doesn't work
		perform action 1 of screenMirroringButton
		delay 0.5
		set myScreen to checkbox 1 of its scroll area 1 of group 1
		perform action 1 of myScreen
	end tell
	
	
end tell

end tell