Show/Hide Hidden Finder Items Via My First Script. Enjoy

I just asked a lot in another topic I made, so I’ll give to the community a bit for compensation :P. I made this last night and it’s the first Applescript I’ve ever written, but it works perfectly fine. Basically, if you say T, then it shows all the hidden stuff, and if you say anything else besides T, it runs it with the false boolean and nothing happens.

tell application "Terminal"
	activate
	set x to 0.5
	display dialog "Show All Finder Files (T/F):" default answer "T"
	copy the result as list to {Answer}
	if Answer is "T" then
		do script "defaults write com.apple.finder AppleShowAllFiles TRUE"
		delay x
		do script "killall Finder"
		delay x
		quit
	else
		do script "defaults write com.apple.finder AppleShowAllFiles FALSE"
		delay x
		do script "killall Finder"
		delay x
		quit
	end if
end tell

Hi Sk8.4.Life,

It is not necessary to use or have Terminal Activate. :wink:

Have a Look at this thread. In particular post #5

Hi,

I wrote a similar one which just toggles the status

quit application "Finder"
set b to (((do shell script "defaults read com.apple.finder AppleShowAllFiles") is "ON") as integer) + 1
do shell script "defaults write com.apple.finder AppleShowAllFiles O" & item b of {"N", "FF"}
delay 1
launch application "Finder"

it’s better to add “-bool” in the script:

Yes, but in Tiger it works also with a string ON or OFF

:slight_smile:

use “do shell script” without calling ‘terminal’


set x to 0.5
display dialog "Show All Finder Files (T/F):" default answer "T"
copy the result as list to {Answer}
if Answer is "T" then
	do shell script "defaults write com.apple.finder AppleShowAllFiles -bool true"
	delay x
	do shell script "killall Finder"
else
	do shell script "defaults write com.apple.finder AppleShowAllFiles -bool false"
	delay x
	do shell script "killall Finder"
end if


Heh, thanks everyone for the input. I especially like elegant’s take on the script. I learned a thing or two here and I’m quite thankfull. :smiley: