I usually need to see all hidden files in Finder, so I used to just have them showing all the time. Being a long time Gnome user (and an Ubuntu one) I learned to love the joy of Ctrl-H to toggle between visible and invisible hidden files, so I thought that Cmd-H would do the same, which it doesn’t.
Seeing hidden files all the time wouldn’t be bad if not for the behated .DS_Store files showing up in every folder and, worst of all, in my Desktop! I try to keep my Desktop clean, no icons at all, just beautiful pictures I get from the nice Kuvva app. I don’t use Desktop shortcuts anyway, Spotlight is my friend.
So, there is a way to add the Ctrl-H behavior to Mac OS, kinda-sorta, and this is the best I could get so far.
Step 1: create a simple shell script
The command to show/hide hidden files is
defaults write com.apple.Finder AppleShowAllFiles YES, changing the last word to
NO if you want to hide hidden files again.
To make the shortcut behave as a toggle, we just create a “sentinel” hidden file (we created a hidden file for your hidden files so you can hide your hidden files etc..) to save the current state.
Here’s the script
if [[ -f .hiddenindeed ]]; then
defaults write com.apple.Finder AppleShowAllFiles NO
defaults write com.apple.Finder AppleShowAllFiles YES
As you may have noticed, we
kill Finder so it reloads the defaults, otherwise it looks like nothing happens. Finder reloads itself, so it’s safe to kill it. There’s a little gotcha: at least in Lion it looks like it doesn’t save its current state all the time, so run the script only when you don’t care about the currently open windows. Results may vary, and even in Lion as I said the behavior is not 100% consistent.
Step 2: save the script with a .command extension and make it executable
I’m not entirely sure that this is needed in Mac OS, but I’m too lazy to check. Plus, it’s super easy and it’s the same thing you would do in Linux.
To make it executable, just open a terminal and type
chmod a+x your_script_name.command
Of course you need to
cd into the same folder as your script, or use the absolute path of your script from whatever folder.
Step 3: choose your preferred keyboard shortcut tool
Ok so this is where you can choose how to launch the script. I strongly prefer the OSX-ified Ubuntu-esque way of just pressing Cmd-H (Cmd being OSX’s Ctrl in most cases) since I never use the shortcut to hide windows, and it’s what comes most natural to me. However, this requires using a third-party tool to launch apps using shortcuts; my weapon of choice is the awesome Better Touch Tool, which I already use to enable 3-finger-click gestures to open links in new background browser tabs (again, this is the equivalent of Gnome’s middle-button click with an external mouse).
There are several alternatives, the most popular being Alfred, I guess. I never felt the need for leaving spotlight thus far, so I don’t know much about how you configure shortcuts for that, but I read it’s one of its features.
Step 3a: using Better Touch Tool
This is very easy: open BTT’s preferences, go to Global (left column, should be selected by default), Keyboard tab, click on the “Add new shortcut” button, click on the Keyboard Shortcut field, press your shortcut of choice and choose “Open Application/File/Script…” from the rightmost menu. Then, select your script.
Step 3b: using Spotlight
You can always type the name of your script in spotlight and select it; the downside to this is that it may never become the Top Hit, or at least it didn’t when I tried, so you’d have to select it with the arrow keys..
Step 4: hide the terminal once the script is done
I don’t want the terminal to stick around even after the script is done, so I have it close automatically when done.
Open a terminal window, go to Terminal/Preferences/Settings tab/Shell sub-tab and change the value for “When the shell exits”. I chose “Close if the shell exited cleanly”, but you can also choose “Close the window”. I like to see error messages if something goes wrong, though..