Reader Jeff tipped us off to a few Terminal commands that hide all your desktop icons for a distraction-free desktop, while keeping Finder functional. In researching a way to write an AppleScript that toggles this function, I found that blogger Jim Mitchell had already done just that:
on run try set _theVar to ((do shell script "defaults read com.apple.finder CreateDesktop") as integer) as boolean on error — if the default value doesn't already exist, create it... do shell script "defaults write com.apple.finder CreateDesktop 1" set _theVar to ((do shell script "defaults read com.apple.finder CreateDesktop") as integer) as boolean end try do shell script "defaults write com.apple.finder CreateDesktop " & (((not _theVar) as integer) as string) do shell script "killall Finder" end run
The most versatile way to use this AppleScript would be to throw it into Automator and create a simple one-click switch. To do so, just open up Automator and choose Service as a template. At the top of the workflow, select Finder for the right drop-down box and "no input" for the left drop-down (so it reads "Service receives no input from Finder". Then, find the "Run AppleScript" action in the left sidebar and drag it into the workflow.
Next, paste the above code into the Run AppleScript box (replacing everything that was there). Save the Service as "Toggle Clean Desktop", or whatever other title you like, and it will be accessible from the Finder > Services menu in the menu bar. If you like, you can even assign a keyboard shortcut under System Preferences > Keyboard > Keyboard Shortcuts. Check out the video above for a demonstration. Thanks to Jeff for alerting us to the original Terminal commands!
AppleScript to Toggle the Desktop [Jimmitchell.org]