If you wish to keep your MacOS desktop clean and free from any distractions, you can easily toggle the visibility of desktop icons. Below, I've provided two scripts that allow you to hide or show the desktop icons.
Create a new file named show_icons.sh
and copy-paste the following content into it:
#!/bin/bash defaults write com.apple.finder CreateDesktop true killall Finder
Create another new file named hide_icons.sh
and copy-paste the following content into it:
#!/bin/bash defaults write com.apple.finder CreateDesktop false killall Finder
Once you've created the scripts, you need to grant them permission to be executed. Run the following commands in your terminal:
chmod +x show_icons.sh chmod +x hide_icons.sh
To show the desktop icons, simply run:
./show_icons.sh
And to hide the icons:
./hide_icons.sh