12

I came to understand that the following is the way to toggle the visibility of hidden files:

defaults write com.apple.finder AppleShowAllFiles YES
# replace YES with NO to hide hidden files
killall -HUP Finder /System/Library/CoreServices/Finder.app

Is there a way to show/hide hidden files without killing the Finder?

5

Edit: This no longer appears to work since El Capitan. killall Finder seems to be the only way now.

This is my current El Capitan method, which should also work for Mountain Lion & older

set newHiddenVisiblesState to "YES"
try
    set oldHiddenVisiblesState to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if oldHiddenVisiblesState is in {"1", "YES"} then
        set newHiddenVisiblesState to "NO"
    end if
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenVisiblesState & "; killall Finder"

For Mavericks & Yosemite…

You don't need to restart the Finder, only refresh the windows.

This Applescript will toggle the state & refresh...

set newHiddenVisiblesState to "YES"
try
    set oldHiddenVisiblesState to do shell script "defaults read com.apple.finder AppleShowAllFiles"
    if oldHiddenVisiblesState is in {"1", "YES"} then
        set newHiddenVisiblesState to "NO"
    end if
end try
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenVisiblesState


tell application "Finder"
    set theWindows to every Finder window
    repeat with i from 1 to number of items in theWindows
        set this_item to item i of theWindows
        set theView to current view of this_item
        if theView is list view then
            set current view of this_item to icon view
        else
            set current view of this_item to list view

        end if
        set current view of this_item to theView
    end repeat
end tell

Credit to ganbustein for the improved hide/show routine

  • You don't need the tell application "System Events" block around the two do shell script ... commands. In fact, I'm surprised System Events allows you to tell it to invoke do shell script. – ganbustein Jan 23 '15 at 6:05
  • I'm no expert in it - I've always just used system events if i don't appear to have 'anybody in particular' to tell;-) – Tetsujin Jan 23 '15 at 7:00
  • 2
    It "always worked" because System Events is returning an error code that means "do it yourself", and the script is silently doing just that to handle the error. The problem is that you would be invoking do shell script with some other app's privileges without giving it a chance to vet the script. Apple made that change to close a security hole where you could ask a program running as root to do your script for you. – ganbustein Jan 23 '15 at 7:26
  • 1
    @ganbustein I've pasted your version into a couple of other places on SE I've used this in an answer. Thanks for the input. Most appreciated. – Tetsujin Jan 23 '15 at 7:40
  • This is great, except that it doesn't change the Desktop itself. Is there was a way to do that too, other than restarting the Finder? – TJ Luoma Feb 2 '15 at 12:31
10

On macOS Sierra, version 10.12.4 and above, you can press +Shift+. (period), to toggle hidden files inside of Finder.

Late edit: This currently works on Mojave too, as of b5, 18 Aug 2018.

  • @fd0, It states, "... to toggle hidden files inside of Finder.", and the key word here is "toggle", which typically implies pressing the same shortcut key combo both hides/unhides hidden files in this use case. +1 – user3439894 Jul 23 '17 at 21:26
  • Do you know the equivalent on non-US versions ? – ogerard Mar 10 '18 at 12:56
  • Don't forget that you can use that same keyboard combination in Open/Save dialog boxes to temporarily show hidden files. – boris42 May 7 '18 at 4:13
  • Still works in Apr 2019! – SilverWolf Apr 30 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .