Logic conundrum - Clear Finder of Icons - Toggle

Hi

I have just coded this to toggle my icons appearing. But it will not actually work. If I enter the commands in Terminal, it works. So I am stumped. Any suggestions?


if (do shell script "defaults read com.apple.finder CreateDesktop") is false then
	do shell script "defaults write com.apple.finder CreateDesktop true"
else
	do shell script "defaults write com.apple.finder CreateDesktop false"
end if
delay 1
do shell script "killall Finder"

Thanks

Model: Macbook Pro
AppleScript: Latest
Browser: Safari 601.3.9
Operating System: Mac OS X (10.10)

Hey There,

On my system:

[format]defaults read com.apple.finder CreateDesktop[/format]

Produces an output of “1”.

Even if it was “true” or “TRUE” it would not be true in the boolean AppleScript sense, because it would be a test value.

If you search MacScripter for “defaults read com.apple.finder” you’ll get a few hits to look at for reference.


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.6 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

On mine, it produces the error “The domain/default pair of (/Blah/blah/Library/Preferences/com.apple.finder, CreateDesktop) does not exist” ” meaning that the CreateDesktop value ” if there is one ” hasn’t been changed from the factory setting. Ideally, a toggling script needs to test if the defaults contain the non-factory setting. If not, the setting’s either not included or has been explicitly set to the factory value. The factory setting here is apparently true (or 1), so the setting for which to test is 0 (= false). To change the setting to true, you can either set it explicitly or delete it.


if ((do shell script "defaults read com.apple.finder") contains "CreateDesktop = 0") then
	do shell script "defaults delete com.apple.finder CreateDesktop"
else
	do shell script "defaults write com.apple.finder CreateDesktop -bool false"
end if
delay 1
do shell script "killall Finder"