Skip to content

Instantly share code, notes, and snippets.

@jimmitchell
Last active June 8, 2023 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmitchell/fdd7a467c839ee740bd0 to your computer and use it in GitHub Desktop.
Save jimmitchell/fdd7a467c839ee740bd0 to your computer and use it in GitHub Desktop.
AppleScript to Toggle the Desktop
tell application "System Events"
set frontMostApp to short name of the first process whose frontmost is true
end tell
try
set theDefault 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 theDefault 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 theDefault) as integer) as string)
tell application "Finder" to quit
delay 1
tell application "Finder" to launch
tell application "System Events"
set the frontmost of process frontMostApp to true
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment