This script command lets you set or toggle the macOS system appearance.
Read more about Raycast Script Commands here.
I wouldn't expect issues supporting a wide range of Mac hardware and macOS versions, however this has only been tested on M1 MBPs.