Unfortunately we cannot get your script above to work in Sonoma 14.6.1.
When it's enabled via Jamf Pro, upon reboot/log-out: mirroring,
(default) primary screen settings are lost & log-in fields migrate
randomly. In our case, similar to the original ...