Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Toggle show or hide hidden files - FIXED' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle show or hide hidden files - FIXED
Authored by: rselph on Apr 10, '03 02:09:13PM
Try this:
tell application "Finder" to quit
set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if inOff= "NO" or inOff= "OFF" then
	set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
	set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if
do shell script OnOffCommand
delay 1
tell application "Finder" to launch


[ Reply to This | # ]
Wierd....
Authored by: rselph on Apr 10, '03 02:13:39PM

Strange. I pasted in the above code, but something on the web site decided to change it just a little bit.

The variable in the "if" clause should be "OnOff", not "inOff" as shown above.



[ Reply to This | # ]
Wierd....
Authored by: frogstomp on Apr 10, '03 02:26:32PM

Yes it works now, nice!

One question though. Now and again I revieve an error
message the "the connection is invalid" I believe on the finder
quit line.

What's up with that?
Is it a limitation with scripting the finder?

Thanks, I like this script the most since it is originally what I
wanted ... Strangely enough though, the reason I wrote mine
was to try and avoid the error message I mentioned here. It
does seem to occur with my script also though, and any script
with "tell application "Finder" to quit" from time to time.

odd...



[ Reply to This | # ]
Wierd....
Authored by: rselph on Apr 10, '03 03:12:42PM

I haven't seen that myself, and I'm not enough of an Apple Script expert to know anything about it. Sorry.



[ Reply to This | # ]
Beat me to the punch
Authored by: jecwobble on Apr 11, '03 12:35:12AM
I wasn't at my Mac when I read this hint, so I couldn't test anything until just now. I merged two of the concepts above and came up with something very similar to yor fix, but I included a "try" statement that may alleviate some of the "connection failed" errors.
set OnOff to do shell script "defaults read com.apple.finder AppleShowAllFiles"
if inOff= "NO" or inOff= "OFF" then
        set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles ON"
else
        set OnOffCommand to "defaults write com.apple.finder AppleShowAllFiles OFF"
end if
try
        tell application "Finder" to quit
        do shell script OnOffCommand
        delay 1
        tell application "Finder" to launch
end try


[ Reply to This | # ]
Beat me to the punch
Authored by: Kool on Apr 11, '03 08:14:55AM
This only works once the preference is once set. So it is needed to at least once type "defaults write com.apple.finder AppleShowAllFiles ON" in the Terminal (or set it with TinkerTool, or any other utility that does this...)

[ Reply to This | # ]
Another way
Authored by: DanCleaver on May 13, '10 03:49:27PM

Just a thought, but you can get around problems with quitting and launching the finder mid-script by setting the default the killing the finder:

display dialog "Show Hidden Files..." buttons {"ON", "OFF"} default button 2
copy the result as list to {buttonpressed}

try
if the buttonpressed is "OFF" then do shell script ¬
"defaults write com.apple.finder AppleShowAllFiles OFF"
if the buttonpressed is "ON" then do shell script ¬
"defaults write com.apple.finder AppleShowAllFiles ON"
end try
do shell script "killall Finder"



[ Reply to This | # ]
!!! THIS IS THE MOST ELEGANT CODE !!!
Authored by: theHub on Jun 11, '10 03:00:29PM
DanCleaver (above) posted the simple (elegant) answer, but I also liked the idea of a "Cancel" button mentioned by one of the other posters. Following the general rule of Least Harmful by Default...

display dialog "¿ Show Hidden Files ?" buttons {"Yes", "No", "Cancel"} default button 3
copy the result as list to {buttonpressed}

try
	if the buttonpressed is "Cancel" then quit
	if the buttonpressed is "No" then do shell script ¬
		"defaults write com.apple.finder AppleShowAllFiles OFF"
	if the buttonpressed is "Yes" then do shell script ¬
		"defaults write com.apple.finder AppleShowAllFiles ON"
end try
do shell script "killall Finder"
Thanx DanCleaver.

[ Reply to This | # ]
!!! OF COURSE YOU COULD COMBINE !!!
Authored by: theHub on Jun 11, '10 05:41:08PM
the second if statement of the try thus...
	if the buttonpressed is "No" then
		do shell script ¬
			"defaults write com.apple.finder AppleShowAllFiles OFF"
	else
		do shell script ¬
			"defaults write com.apple.finder AppleShowAllFiles ON"
	end if


[ Reply to This | # ]