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


Click here to return to the 'Beat me to the punch' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]