To run this script
Select Script → Layout → Toggle_Background_Color from the Menus.
Or in Version 13 or higher you can run the utility directly from this page using this button.
This script changes the layout background color to black if it is white or to white if it is black. Below is an example of two layout windows before and after the code is run.