May 01 2008
Toggle Finder Hidden File Status
For some reason I prefer to have system files (hidden by default) shown in Finder (must be the Unix in my system from grad school). With that said, there are times when it would be nice to have these same files out of sight when working with a cluttered folder. After having thought many times about writing a short script to toggle hidden files on/off, I finally took a few minutes to crank out the code below:
Script Editor Click to paste code into the Script Editor
----------------------------------------
-- MacDeveloperTips.com
-- Toggle Finder hidden file status
----------------------------------------
try
-- Get current value
set toggle to do shell script "defaults read com.apple.finder AppleShowAllFiles"
-- Toggle it
if toggle = "ON" then
do shell script "defaults write com.apple.finder AppleShowAllFiles OFF"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles ON
end if
-- Restart Finder
tell application "Finder" to quit
delay 0.5 -- If you have problems, you can tweak the delay
tell application "Finder" to launch
on error
display dialog "Unable to toggle bit status." buttons {"Better luck next time"}
with icon caution with title "Error"
end try
Notice the reference to delay – if you have problems with the scripting not running properly, you can experiment with a longer delay. There is minimal error handling, essentially just trapping errors and displaying the message below:
I prefer to save AppleScript code as an application, create an icon that serves as a reminder of what the script does, and drag/drop the application onto the Finder toolbar. You can see a screenshot below what my toolbar looks like (the icon for this script is the blue & white Finder image).
And speaking of icons, in an upcoming tip I’ll show you how easy it is to change an application icon on a Mac.
Tips by RSS
Tips by Email