Aug 17, '05 09:17:00AM • Contributed by: jacobolus
Quite a long time ago, this hint explained how to use the command line to make the Finder show all those hidden unix files. I turned it into a little shell script, and stuck it where I could find it. Then more recently, a bunch of AppleScript solutions were hinted at, in a thread that started in mid 2003, and had still more postings as of a couple of months ago.
Now with Tiger, however, it's possible to make showing such files a contextual menu selection via Automator. I made an Automator action called 'Show/hide unix files,' and told Automator to save the file as a plug-in for the Finder. Read on for the details...
There are two steps in the workflow; one shell script to show/hide the files, and one AppleScript to quit the Finder and restart it, so the changes can be immediately seen. The scripts were compiled from some knowledge of the bash shell, and some help from the posters on the original hints. I particularly like the error checking provided by 'hofman' (so my AppleScript is basically his).
Launch Automator, and add the Action named Run Shell Script, with the shell set to /bin/bash, and the script set to the following:
showFiles="$(defaults read com.apple.finder AppleShowAllFiles)"
if [ "$showFiles" = 1 ]
then defaults write com.apple.finder AppleShowAllFiles -bool FALSE
else defaults write com.apple.finder AppleShowAllFiles -bool TRUE
fi
This figures out whether the hidden files are currently showing, and then executes the appropriate command to toggle the preference. Next, add the Action called Run AppleScript, with the script set to this:
try
tell application "Finder" to quit
on error
-- Note that the error line below is shown on two lines
-- (in order to narrow the display here on macosxhints),
-- but must be entered as one line; just remove the line break
error "Unable to quit Finder. You may want to try force quitting it
(Command-Option-Escape) to have the change take effect."
end try
set finderIsActive to false
set errorCount to 0
repeat until finderIsActive
try
tell application "Finder" to activate
set finderIsActive to true
on error
set errorCount to errorCount + 1
if (errorCount > 30) then
-- Note that the error line below is shown on two lines
-- (in order to narrow the display here on macosxhints),
-- but must be entered as one line; just remove the line break
error "Unable to restart Finder. Please click the Finder
icon in the dock to restart it."
end if
delay 0.1
end try
end repeat
This code tries to quit the Finder, presenting an error message if it doesn't work, then tries to restart the Finder every tenth of a second for three seconds until it either succeeds, or gives up upon failure, and presents another error message
Now all that's left is to save the file: Choose File -> Save As Plug-in, give it a name, and make sure the pop-up menu is set to Finder. You're done! All those unix files are now just a control- or right-click away.
