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.
-
apple.stackexchange.com/questions/168540/… might help here– nohillside ♦Commented Mar 17, 2015 at 15:29
3 Answers
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
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
-
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 whenAppleShowAllFiles
is set toYES
. 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 tokillall Finder
? Commented Mar 17, 2015 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'– TetsujinCommented Mar 17, 2015 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. Commented Mar 17, 2015 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– TetsujinCommented Mar 17, 2015 at 16:55
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 ♦Commented May 5, 2017 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. Commented May 7, 2017 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 ♦Commented May 7, 2017 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 !– OdeklasCommented Jul 16, 2017 at 23:27
If you're using the French AZERTY keyboard, the default shortcut is different because the dot can only be typed by pressing Shift + ;
In this particular case, use this shortcut to toggle hidden file display in Finder: Fn + Cmd + Shift + ;
Source: Keyboard shortcut to show hidden files on macOS Big Sur