8

I want my Mac to show hidden files when i hit ⌘ + H (like ubuntu). I can see hidden files by putting this defaults write com.apple.finder AppleShowAllFiles YES command in terminal but i want to get a keyboard shortcut for it. Also, if ⌘ + H is already used by some other process please let me know what might be the closest and most related shortcut for this new process and how to assign it to the respective, show hidden files process.

12

Edit at Nov 2018
This is all now moot since High Sierra. In Finder, Cmd ⌘ Shift ⇧ . [period, full stop] will toggle invisible files on the fly, nothing else needed.


Cmd ⌘ H is the system-wide shortcut for "Hide frontmost app"

To try tie a new shortcut to that, you could maybe use Automator to add a Service - but I still don't know how you would persuade it to override the existing System default.

This works as a Service if you use a non-system key, but not with Cmd ⌘ H

on run {input, parameters}

    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

    return input
end run

Edit for El Capitan…
I've noticed that the Finder window refresh no longer works in El Capitan, so this is a modified version, quitting the Finder instead.

on run {input, parameters}      
    --Toggle Invisibles, El Capitan Version     
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"
end run

enter image description here

I guess you could make it work for the Finder only, if you specified some other key command for Hide Finder - as it is visible as a Menu item it would be possible to override for that app alone [by putting something 'useless' as an alternative], leaving you free to then use Cmd ⌘ H to toggle invisibles from the Finder only.

Tested - does work this way

enter image description here


enter image description here

  • The source code does not work as written in Automator under OS X 10.8.5. without modifying and adding killall Finder. In other words just refreshing the Finder windows doesn't show the hidden files/folders when AppleShowAllFiles is set to YES. I did test the source code, as is, in Automator under OS X 10.10.2 and it does work as written. Any way to make it work in OS X 10.8.5 without resorting to killall Finder? – user3439894 Mar 17 '15 at 16:09
  • Might possibly be OS 10.9 is the earliest you can change the view without restarting the Finder. You can make the Finder Quit by Applescript, - lose the entire 'tell application "Finder" ' part right to the 'end tell' & just replace with tell 'application "Finder" to quit' – Tetsujin Mar 17 '15 at 16:15
  • Yeah, however even though you can programmatically gracefully quit/open Finder it doesn't reopen opened Finder windows like "killall Finder" does. Thanks though for the script, I'll use it under OS X 10.10.x. in my virtual machine. Still using OS X 10.8.5 as my primary. – user3439894 Mar 17 '15 at 16:25
  • It used to for me - though I don't have the old version any more where I used to quit Finder to do this - haven't used 10.8 in quite some time. hm… I remember I had a routine to make sure it has restarted, but don't remember the details any more – Tetsujin Mar 17 '15 at 16:55
2

Cmd ⌘ Shift ⇧ . will toggle hidden file display in the finder(In Sierra or later(but works in the open file dialogue in earlier versions)).

  • This only works for file open/save sheets, not Finder windows in general. (It's been in macOS for many years.) – grg May 5 '17 at 18:59
  • Like I said, it might be a new feature. I'm running Sierra on my work computer and it works perfectly in an ordinary Finder window. But only in list mode and that multi-column mode; not in icon mode. – Edward Falk May 7 '17 at 4:18
  • Sure, I didn’t downvote but it’s not working for me in the latest Sierra beta except in file sheets, do you have TotalFinder or such? – grg May 7 '17 at 7:12
  • This might be a new feature, but on Sierra, Cmd ⌘ Shift ⇧ . will toggle hidden file display in the finder. this worked for me i just had to be in finder and it works ! i tried to give you reputation but i cant ! thanks mate ! – Odeklas Jul 16 '17 at 23:27

You must log in to answer this question.

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