Last active
June 8, 2023 14:17
-
-
Save jimmitchell/fdd7a467c839ee740bd0 to your computer and use it in GitHub Desktop.
AppleScript to Toggle the Desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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