Show or hide invisible files in the Finder

Some UNIX and system files (those beginning with ".") are by default hidden in the Finder. By setting a flag in the Finder preferences, they can be made visible in the Finder, instead.

 

Usage...

No modification of the script is necessary. You can modify the code which display's the dialog messages to customize it, but most of the code is fine as it is.

Code...

(* Determine whether invisibles are currently shown or hidden *)
set plist to POSIX path of (((path to preferences folder from user domain) & "com.apple.finder") as string)

try
	set showingAllFiles to (do shell script ("defaults read " & plist & " AppleShowAllFiles"))
	set showingAllFiles to item (showingAllFiles + 1) of {false, true}
on error
	set showingAllFiles to false
	beep
end try

(* Prompt the user whether they want to toggle file visibility *)
set {tmpMsg, tmpButton} to {"Invisible UNIX files are NOT visible in the Finder.", "Show"}
if showingAllFiles then set {tmpMsg, tmpButton} to {"Invisible UNIX files are visible in the Finder.", "Hide"}

display dialog tmpMsg buttons {"Cancel", tmpButton} default button tmpButton

(* Try to update the visibility flag and relaunch the finder *)
try
	do shell script ("defaults write " & plist & " AppleShowAllFiles -bool " & ((not showingAllFiles) as boolean))
	tell application "Finder" to quit
	delay 1
	tell application "Finder" to activate
	
on error
	display alert "Unable to toggle invisibles!"
end try

Notes...

This code has been modified for use in 10.4 (tiger).

 

 

Hosted by www.Geocities.ws

1