[Update 2] Still in early Mac OS X 10.6 Snow Leopard discovery mode, I’ve started revisiting MacOSXHints.com much more regularly to find out what handy undocumented or at least not widely known tricks the new OS has up it’s sleeve. Today I came across this fantastic tip about how you can toggle the display of hidden files in any standard open/save dialog box just by hitting “Shift+Command+. (period)”. My first reaction of course was, “wow, what a great idea!”, followed quickly by, “about freaking time!” and ultimately, “wtf?, why didn’t they implement this in the Finder?!?”.
Well as the old saying goes, give a man a fish and he can feed himself for a day, teach a man to fish and he can get rich selling fish to other suckers (or something of the sort). So it is that Apple has given us the tools in Snow Leopard to fend for ourselves. Once again, Automator, Services, a custom keyboard shortcut and the good old bash Terminal are all we need to get the job done. Read on for the step by step instructions on how to make “Shift+Command+. (period)” toggle the display of hidden files in Finder.
- Open Automator (in your Applications folder) and choose Service from the list of templates provided and click the Choose button.
- In the left hand column under Library, select Utilities.
- In the second column, drag “Run Shell Script” to the right hand pane.
- At the top of the right hand pane where you dragged the Run Shell Script action, click on the right-hand popup menu and change “any application” to “Finder”. This sets the service so it only appears and can be activated by the keyboard shortcut when Finder is the active application.
- Then click on the popup menu next to “Service receives” and choose “no input”. It’s important you do this step after step 4 because if you do the reverse, Finder won’t be available as an option in the right hand menu.
- Copy and paste the following text into the empty text area of the Run Shell Script action:
- Choose File–>Save, and give the new service a meaningful name like “Toggle Hidden Files” that will appear in the Services menu. Once you’ve done that, you can go to the Services menu (located in the current application menu, next to the Apple menu) and your newly created service should appear there. You can even run it, it’s already fuctional, just lacking a keyboard shortcut.
- Open System Preferences–>Keyboard–>Keyboard Shortcuts and select Services in the left column.
- Scroll down to the bottom and under the General category, you should see your newly created service listed there. Select it, then Double-click close to the right side of the selected line to reveal a field where you can enter a custom keyboard shortcut. Enter “Shift+Command+.” (might as well keep it consistent with the shortcut used in open/save dialog boxes), and then quit System Preferences.
osascript -e 'tell application "Finder" to quit'
SHOWHIDDEN=`defaults read com.apple.finder AppleShowAllFiles`
if [ $SHOWHIDDEN -eq 1 ]; then
defaults write com.apple.finder AppleShowAllFiles -bool FALSE
else
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
fi
osascript -e 'tell application "Finder" to activate'
That’s all there is to it. The really nice thing is built-in keyboard shortcuts override custom ones, so pressing “Shift+Command+. (period)” in an open/save dialog will not execute this service.
The way the script works is to toggle the state of a hidden Finder preference and restart the Finder so the changes take effect. So you will see Finder disappear momentarily when executing this service.
Since the Finder will be restarted cleanly (using an AppleScript call to request it to quit), any tasks it is currently executing such as a copy operation, emptying the trash, etc. will prevent Finder from quitting and pop up the two error messages displayed on the right, without any modification to Finder’s preference plist file. If this happens, simply click “OK” to clear the two messages, wait for the Finder operation to complete (or cancel it) and try again.
I’ll reiterate how dumb it is that we have to implement this ourselves, but this oversight seems completely insignificant when we consider that instead of implementing a single keyboard shortcut that less than 1% of users will ever use, Apple have given all users a powerful and easy to use set of tools to add a keyboard shortcut for almost anything they could ever want to accomplish with one. Now go fish!
Update 1 – 9/17/2009, 11:20 pm: I’ve made a slight modification to the instructions, adding step 4 which makes the service (and keyboard shortcut) only active when Finder is the frontmost app. This greatly reduces the chances that the keyboard shortcut will interfere with one already assigned to an application, but also keeps the Services menu less cluttered when not in Finder. This also makes it impossible to accidentally activate the service unintentionally unless Finder is the active app. Seeing as you’d only really want/need to use this trick while using Finder, this made the most sense, but of course you’re welcome to leave this step out if you think you might want to toggle this while running any app.
I also added two extra lines at the end of the shells script to improve usabiliy. Previously, after the action was executed, Finder would in most cases not end up being the frontmost application anymore since upon quitting Finder, the next application that is running would now become frontmost. The added two lines simply add a quarter second pause so Finder has a chance to relaunch before running the open command which brings Finder back to the front if it isn’t already.
Update 2 – 10/2/2009, 11:57 am: Special thanks to commenter “GlowingApple” for a suggested improvement to use the osascript command to politely quit the Finder rather than the killall command. The benefit is now Finder will throw up an error if it’s in the middle of doing something rather than simply imploding taking your copy or empty trash command with it.
I also changed the execution order a little bit so that the Finder is quit first before the plist modification takes place. That way if the Finder can’t be quit because it’s busy, no change will take place. This will prevent the state of hidden file display from unexpectedly changing between reboots or logouts if you unsuccessfully executed the service and Finder couldn’t be quit.





Great hint (from MacOSXHints) for the Open/Save Dialog file visibility toggle) and to you for working in a way to get it to work for the Finder!
Great tip! Thanks for sharing.
Outstanding work! Thanks!
Thanks – this is great, I was using a download called “Invisibles” that was wonky as all get out and half the time the finder wouldn’t come back. This is clean and easy.
Thanks for the great tip. This solves a lot of time wasting and frustration.
If OS X can do it in Open/Save dialogs without restarting Finder, then obviously there is a different setting or procedure that Apple uses. It would be great if you could find out what that is.
Quite possibly, and if I find out, I’ll be sure to update this post! But keep in mind that the Open/Save dialog boxes are NOT handled by Finder, so just because the feature is there in the dialogs, does not necessarily mean it’s been implemented in Finder, or that it’s available to be called with a simple shell or AppleScript call.
How can I make all those files invisible again. Running the services action again does not make them invisible (only can make visible)?
Running it again will hide them again. If not, then you did something wrong. To hide the files manually, just execute these two terminal commands, one after another (which is what the service does):
defaults write com.apple.finder AppleShowAllFiles -bool FALSEkillall Finder
To restore my finder preferences so that I would not have to continual and always see all those invisible files (in every folder) I trashed the following files from my home/library/preferences folder: com.apple.finder.plist and com.apple.launchservices.plist. I then restarted and didn’t have the problem thereafter.
Trashing com.apple.finder.plist and restarting Finder (or restarting your Mac) should have sufficed since that’s the only file the service modifies.
Thanks for this, is there a way to delete a service? I couldn’t figure out how to change the name on the first one i created (called it toggle hidden folders) so i created another one & just called it toggle. I realized that the point of making something hidden was not to make it obvious how to find it. Also, is there a way to make the service active & not show it in the menu?
You’ll find Services exactly where you’d expect Apple to put them:
‘~/Library/Services/’
The “~” in Unix speak means your home folder.
Just delete the service you don’t want from there. Be aware that renaming the service file will not rename it in the menu. You’ll need to open in Automator and re-save it as a new name to do that.
Hmm!
Redid everything and it all works properly now.
Thanx much.
awesome tip, thanks!
Very useful – certainly beats needing to install another app or for that matter opening the terminal.
I haven’t tried this to see if it would work any better, but instead of killing the Finder process, you could use AppleScript to “gracefully” exit Finder and then reopen it:
osascript -e ‘tell app “Finder” to quit’ && osascript -e ‘tell app “Finder” to activate’
(in place of killall Finder)
If Finder is in the middle of some process it will send an error back via Applescript, so the service would just terminate with an error, rather than canceling the Finder operation.
Thanks GlowingApple! That is an improvement and worked like a charm! I’ll update my post with the new shell script.
Hi – thanks for the guide, but didn’t work for me – the toggle works ok, but finder doesn’t start back up again afterwards – if I start it manually using the dock icon everything comes back as it was but with the setting toggled – any idea what I may’ve done wrong?
Cheers!
hmm ok that’s strange, a few minutes later and now it’s working just fine.. but I didn’t change anything
guess may have something to do with the first time I tried this the active window was a mounted disk image, or maybe it just takes a while to kick in/not sure..
Thanks a lot for this great tips!
This script looks useful but I cannot get it to work. It does nothing but quit Finder. When I run the script from within Automator, it quits Finder then stops at the second line with this error:
SHOWHIDDEN=1: Command not found.
Problem solved: Automator was set for a tcsh shell but needed to be set for an sh shell. But then another small problem showed itself: I needed to add a line sleeping the script for 1.5 seconds.
Actually, you should be using /bin/bash as your shell, that’s probably why it isn’t working as instructed for you. /bin/bash is the default shell for Mac OS X, which is probably why I didn’t think to mention it, however if you look closely at my Automator screenshot, you’ll see that’s what’s set.
Try it with that and see if that allows the service to work without the 1.5 second delay.
It doesn’t work at all using /bin/bash, either with or without the delay. Finder error: invalid connection.
AWESOME !!!!!!!!!!!!!!!
YMMD
Thanks a million!
[...] found this tip at artofgeek.com, tried it on my MacPro running Snow Leopard and it works like a [...]
THANKS!
Just what I needed
I have followed your instructions precisely but have hit a roadblock.
Somehow the Service only gets me to the point where the Finder quits – nothing occurs after that and when I manually relaunch the Finder the invisible files have not been toggled on.
This is on Snow Leopard with all latest updates. Any thoughts on what might be preventing the shell script from fully executing?
Many thanks.
Scott,
Make sure you are copying and pasting the entire contents of the shell script from above into the Automator Run Shell Script action. Do NOT type it in manually as doing so could introduce typos. Also make sure in the action that /bin/bash is set as the Shell. Click on the screenshot below step 6 and compare it carefully to what you have in Automator just before you save the service. The Shell setting and the script itself are the only places I can think you could have gone wrong. Good luck!
Excellent – you nailed it. The problem was that the action wasn’t set for “/bin/bash” but rather for another selection. Changing that in the drop-down menu and then saving the workflow did it. (I had done the copy/paste you suggested in the first iteration… I never trust anything to be re-typed when it can be copied.)
Many thanks for a great Service item and for your very quick response. Much appreciated.
Great tutorial. Thanks for the help!
When I open Automator to enter the script, there is no “Utility” entry in Library.
I’m running 10.6.2.
Hmmm, something is definitely messed up in your install if that’s truly the case that there’s no “Utilities” category, but you might still have the Automator action “Run shell script”, just select the Library to view all actions and scroll down.
[...] found this script to be of help so I could toggle display of hidden files in FInder: Toggle display of hidden files in Finder with keyboard shortcut I realize the use of /private/etc works in the finder but I always had the same setting in windows. [...]
Thanks for this, I was using terminal to manually find and remove unused files and ran into a problem doing it that way. Nicely written and easy to follow tips are my favourite ones!
Thank you for this gem of a tutorial. The service works fine, but the re-opening of the finder is intermittent. I can’t discern a pattern in the behavior, though. Even so, I find both the service and the tutorial invaluable!
Added observation re: inconsistency in behavior:
It seems that whenever the finder windows reopen correctly, they also position properly to location of sidebar selection, if appropriate. When the windows don’t open up, then opening a window results in selection starting from the root directory “/”, with no sidebar selection.
On my brand new 27″ iMac Core i7, I have the same problem with Finder not opening again unless I sleep for 1.5 seconds at the end of the script. I am using /bin/bash so that’s not the issue. I think it’s a problem with timing. My guess is that people with slower cpus are not seeing the problem.
I Googled?Binged – SPECIFICALLY – for show hidden files in snow leopard 10.6.2 and got to this post!
(as with many posts before) … nothing works.
So MY question is, does anyone REALLY KNOW how to show hidden files in the 10.6.2 version … without directing me – AGAIN – to a solution for the 10.6 vrsion.
OBVIOUSLY there IS a difference (did Apple discover that already by themselves ??? )
wondering
Mitch,
This trick works in 10.6.2. If it’s not working for you then you’re likely doing something wrong. To show hidden files the manual way, open Terminal and type in the following all on one line:
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
After hitting return, simply restart the Finder. To reverse the change use the same command but with FALSE instead of TRUE at the end and restart the Finder again.
How run or open selected object in FINDER with keyboard shortcuts? When I press Enter, it just do Renaming. Do I must double click with my magic? Excuse me, Mac is too new for me… Wish me luck!
Hi Erdee,
Command+O is the keyboard shortcut for opening items in Finder. If you’re new to Macs, I suggest you browse the menus because keyboard shortcuts are always shown next to their commands in the menus at the top of your screen.