Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: A Service to show/hide hidden files System 10.6
Snow Leopard only hintThere are many ways to show and hide the various hidden files and folders in Mac OS X. This one is an update to an older Automator workflow method. The previous method was to create a plug-in in Automator; now a pair of Services are used, so this hint only applies to Snow Leopard. Refer to the previous hint for usage in either Leopard or Tiger.

Here's how to do it:
  • Launch Automator and choose Service as your template. (Be careful in the next steps if you copy and paste the code that the apostrophes and quotes come through as plain text.)
  • On the left side, use the search bar to find the 'Run Shell Script' action (it's in Utilities) and drag three instances of that action over to the right side.
  • At the very top on the right where is says 'Service receives selected' choose 'files or folders' in 'Finder.'
  • In the first 'Run Shell Script' box type the following:
    defaults write com.apple.finder AppleShowAllFiles -bool TRUE
  • In the second box type the following:
    osascript -e 'tell application "Finder" to quit';
  • In the third box type the following:
    osascript -e 'tell application "Finder" to activate';
  • Save the file as Show Hidden Files.
  • Now go back to the first 'Run Shell Script' box at the top and change the word TRUE to FALSE.
  • It should now read:
    defaults write com.apple.finder AppleShowAllFiles -bool FALSE
  • Save this file as Hide Hidden Files.
That's all, now when you right click a file or folder, these options will show up at the bottom of the list.

To delete these Services go to ~/Library/Services and just move both files to the trash.

[crarko adds: I tested this, and it works as described.]
    •    
  • Currently 2.89 / 5
  You rated: 2 / 5 (28 votes cast)
 
[21,651 views]  

10.6: A Service to show/hide hidden files | 22 comments | Create New Account
Click here to return to the '10.6: A Service to show/hide hidden files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: A Service to show/hide hidden files
Authored by: Quatch on Jul 20, '10 08:17:05AM

Probably worthwhile to add a 'ask for confirmation' step prior to the restart. just so you don't do this while a copy or something is going on.



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: karog on Jul 20, '10 08:56:18AM
The 2nd and 3rd Run Shell Scripts can be replaced with a single Run AppleScript containing:
tell application "Finder"
    quit
    activate
end tell
Also, you can put more than one line of shell code in a Run Shell Script so there is no need for three separate ones in the hint.
Edited on Jul 20, '10 09:18:25AM by karog


[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: baltwo on Jul 20, '10 07:20:04PM

Results in:

"Finder got an error: Connection is invalid."



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: MtnBiker on Jul 20, '10 08:58:40AM

Thank you for a helpful hint.

One question: Why doesn't this show up under Finder>Services?

One trivial optional change. Name the Services so they show next to each other, e.g., Hidden Files- SHOW and Hidden Files-HIDE

Or maybe some enterprising scripter can make this service a toggle.

Another nice change would be to have the right click work anywhere in the Finder rather than just a file.

---
Hermosa Beach, CA USA



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: paulw on Jul 20, '10 09:14:22AM
I use the following code for creating the service instead. This toggles between viewing hidden files or not, without calling osascript.

I can't find the original post on the internet where I acquired it, so credit to whoever posted it to begin with.

I set a keyboard shortcut (command-shift-'.') in the keyboard prefpane to activate the service.

SHOWHIDDEN=`defaults read com.apple.finder AppleShowAllFiles`
if [ $SHOWHIDDEN -eq 1 ]; then
defaults write com.apple.finder AppleShowAllFiles -bool FALSE
killall Finder
else
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
killall Finder
fi
sleep 0.25
open /System/Library/CoreServices/Finder.app


[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: mchagers on Jul 21, '10 01:46:52AM

When I tried this script in automator I got the error:
SHOWHIDDEN=1: Command not found
It worked when I changed the shell selection from the default /bin/tcsh to /bin/bash with the popup menu at the top of the Run Shell Scripts block.
Perhaps /bin/tcsh isn't always the default shell, but in my case it was, so this may help some other people as well.



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: mchagers on Jul 21, '10 02:06:33AM

Another thing: Killall Finder causes the Finder to forget the most recent changes to window positions.
using Applescript to quit the Finder ensures that your windows reappear exactly as before invoking the service.



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: MtnBiker on Jul 20, '10 09:31:45AM

Thanks, much prefer a toggle. Found the original here [link:]http://artofgeek.com/2009/09/16/toggle-display-of-hidden-files-in-finder-with-keyboard-shortcut/ where he refers to another Mac OS X Hint that tells us that the same keyboard shortcut (command-shift-'.') works in the Open dialog box.

The script has been updated from the version that paulw used, so read the posting for the reasoning and other details. But here is the updated script (there are three versions, all of which may be useful, but this final one is more generally useful and robust):

<code>
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'
</code>

These Services do show up under Finder>Services if a file is selected, but not if a folder is selected. A bug?

This takes care of two of three of my comments/questions.

PS Is "[link:]" an HTML tag and how do I use it? And sorry for the formatting, toggling HTML is messing things up.

---
Hermosa Beach, CA USA
Edited on Jul 20, '10 09:45:06AM by MtnBiker



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: karog on Jul 20, '10 10:11:16AM

I don't know what the [link:] tag is but if you set the post to HTML Formatted then you can use the <a> tag for links eg

<a href="http://wherever">link text</a>



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: mchagers on Jul 21, '10 01:54:29AM

If you set the Service receives menu to "No input", the service is available in the Services menu without selecting any file or folder in the Finder. Also you can make it available in any Application if you like.



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: chinstrap on Jul 20, '10 01:52:22PM
Alternatively, just wrap the whole thing in a single service called 'Toggle Hidden Files' with a single shell script:

SHOW=`defaults read com.apple.finder AppleShowAllFiles`
if [ "${SHOW}x" = "1x" ]; 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 quit'
osascript -e 'tell application "Finder" to activate'


[ Reply to This | # ]
You can also use the free tool InVisibles
Authored by: tice on Jul 20, '10 02:23:58PM
It's mailware, but works eben without:

Download here

[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: baltwo on Jul 20, '10 07:27:07PM

Alternatively, save this as an AppleScript application, place it on the Dock, and single-click to toggle. Better than using as a service and usable in Tiger and later.

if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is equal to "0" then
      do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
else
      do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
end if
do shell script "killall Finder"

Edited on Jul 20, '10 07:30:59PM by baltwo



[ Reply to This | # ]
Easiest Way
Authored by: fulmar2 on Jul 21, '10 08:40:49AM

Free Utility to do just this. No tinkering required:
http://gotoes.org/sales/ShowHiddenFilesMacOSX/

And, while we're at it, they also have a program to change the visibility of individual files:
http://gotoes.org/sales/ChangeFolderVisibilityMacOSX/



[ Reply to This | # ]
10.6: Toggle show/hide hidden files
Authored by: AragonX on Jul 21, '10 02:11:35PM
Here's the simple Apple Script I use to toggle show/hide hidden files:

tell application "Finder" to quit
try
	set t to (do shell script "defaults read com.apple.finder AppleShowAllFiles") as boolean
on error
	set t to false
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & (not t)
tell application "Finder" to activate


[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: Dimka on Jul 22, '10 11:27:42AM

there is a free dashboard widget that toggles it.
nothing to remember, easy access



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: creamers on Jul 22, '10 01:48:52PM

Awhile ago I made two simple automater apps that do this.

I just used run shell script.

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

It works perfect and I have two of them quite simple.

---
~Wesley K



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: billinand on Jul 26, '10 07:59:00AM

The Show Hidden Files software work perfectly. Thanks fulmar2 for link

---
examine the contents not the bottle



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: kylecara on Jul 30, '10 08:20:47PM

I did this but then when I put them back by putting the command in with False at the end ALL of the folders are still visible in my user folder. Just my User folder, everywhere eles went back to hidden. Any Suggestions?



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: marquis on Jul 21, '11 10:42:28AM
Totalfinder has this feature built into it:
http://totalfinder.binaryage.com/show-system-files
Keystroke shortcut to show/hide dot-files works, even in time machine.

[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: smccandlish on Sep 20, '11 06:10:20PM

You may find that with this and any other script that stops and restarts the finder that you need to introduce a short delay between these two actions to avoid a "Finder got an error: Connection is invalid. (-609)" problem. E.g., in Automator, use the "Pause" action for, say, 5 seconds. Try taking it down to 4, then 3, etc. until you find the shortest delay that will work without generating this error.

---
Stanton McCandlish
Principal, McCandlish Consulting



[ Reply to This | # ]
10.6: A Service to show/hide hidden files
Authored by: smccandlish on Sep 20, '11 10:12:36PM

Better yet, use

sleep 5

between the commands to quit and activate the finder. If you try to do it with a pause in Automator, it may fail to restart the Finder when the service is run from Finder itself but the sleep method gets around this problem. My automator script to do this is:

Service receives: No input
in: Any application

Run Shell Script (Shell: /bin/bash):

SHOW=`defaults read com.apple.finder AppleShowAllFiles`
if [ "${SHOW}x" = "1x" ]; then
   defaults write com.apple.finder AppleShowAllFiles -bool FALSE
else
   defaults write com.apple.finder AppleShowAllFiles -bool TRUE
fi

Ask for Confirmation:

Restart Finder?
Make sure no copy or move operations are in progress.

Run Shell Script (Shell: /bin/bash):

osascript -e 'tell application "Finder" to quit';
sleep 1
osascript -e 'tell application "Finder" to activate';

Works like a charm.

---
Stanton McCandlish
Principal, McCandlish Consulting


[ Reply to This | # ]