Apple - Hotkey to show hidden files and folders in File Open dialog?
⌘ CMD+⇧ SHIFT+. reveals hidden files in Finder and Open/Save dialogs.
If you are using an AZERTY keyboard, you'll need to press fn too, so ⇧ SHIFT is taken into consideration as you already need it to make the ..
You can also press ⌘ CMD+⇧ SHIFT+G and type the path to the hidden folder, just like in Terminal (⇥ TAB autocompletion also works).
Editing hidden files can be dangerous if you don't know what you're doing.
Mateusz Szlosek covered the first part. Below is how I have handled the second part for my own use.
In my haste to post my answer, I did not realize the second part has already has been answered. See How to set ⌘ + H to enable show hidden files. What I offer below differs by a dialog informing you of the current status.
I created a service using the Automator application. When I want to toggle the viewing of hidden files, I select "Toggle Hidden Files" from the Finder services submenu as shown below. (Hint: Click image for a better view.)
This will cause either pop shown below to appear.
The steps to create the service are give below.
- Open the Automator, select a new document of type Service.
- Drag the action "Run Shell Script" to the workflow pane.
Edit the contains to appear as shown below. (Hint: Click image for a better view.)
The text for the script is repeated below.
STATUS=`defaults read com.apple.finder AppleShowAllFiles 2>/dev/null` if [ "$STATUS" == TRUE ]; then STATUS=`osascript -e 'tell app "Finder" to display alert "Finder is showing hidden files." buttons {"Cancel", "Hide"}'` else STATUS=`osascript -e 'tell app "Finder" to display alert "Finder is not showing hidden files." buttons {"Cancel", "Show"}'` fi if [ "$STATUS" == "button returned:Show" ]; then defaults write com.apple.finder AppleShowAllFiles TRUE killall Finder elif [ "$STATUS" == "button returned:Hide" ]; then defaults write com.apple.finder AppleShowAllFiles FALSE killall Finder fi
- Save (or move) the
Toggle Hidden Files.workflow
file to the~/Library/Services
folder. - You may need to relaunch the Finder application in order for the service to appear on a menu.
Update 1
Building off of Mateusz Szlosek's answer, I see the keyboard shortcut ⌘ CMD+⇧ SHIFT+. could be added for my service. Go to System Preferences and click on the Keyboard icon. Select "Services" then "Toggle Hidden Files" under the "General" heading. Replace "none" with the ⌘ CMD+⇧ SHIFT+. keyboard short cut.
DISCLAIMER/WARNING
Hidden files are hidden for a reason usually. Use the script below only if you're reasonably sure you know what you're doing. In other words: If you break your system by randomly deleting hidden files, it's your own fault.
Here's the script I use to toggle show/don't show hidden files inside Finder.
(The OSX native shortcut to toggle hidden files in Open/Save dialogues was mentioned by Mateusz Szlosek above already)
The difference between my script and others I've seen so far:
Most scripts don't do anything else after killing Finder. Usually, this means you have to navigate back to the folder you were in originally, since the automatic Finder relaunch doesn't reliably open your last active folder.
The script below instead reopens, and focuses on, your last active folder, i.e. the folder you were in when using the toggle, but now showing (or not showing) hidden files.
I assigned a shortcut to it (cmd+shift+.) and find working with hidden files in Finder a lot more convenient now.
Credit to Tetsujin who posted a script on this site a while ago that I adapted to add the 'reopen last folder' functionality.
on run {input, parameters}
tell application "Finder"
set var1 to POSIX path of (target of window 1 as alias)
end tell
set newHiddenVisiblesState to "YES"
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
do shell script "defaults write com.apple.finder AppleShowAllFiles " & newHiddenVisiblesState
---- Sleep hack mentioned below. 0.5s minimum, 1-2s safer. Ugly, but (probably) unavoidable.
do shell script "killall Finder; sleep 0.5s"
tell application "Finder"
---- Close other windows if Finder managed to relaunch already
if application "Finder" is running then
close every window
end if
open (var1 as POSIX file)
activate
end tell
end run
To use the script: Open a new workflow in Automator, drag in "Run AppleScript", copy&paste the code above, and save inside your services folder (usually, ~/Library/Services/, afaik).
Attaching a shortcut to execute a script should be covered somewhere else on this site. I limited the scope of my shortcut to Finder alone.
Style remark:
I have to resort to a bit of an ugly hack, using 'sleep' after killing Finder, before manually opening the original folder.
If I don't force this delay, there's a chance OSX relaunched Finder already and opened a folder (not necessarily the last active one, in my experience). Together with my own 'open' command, this can lead to the nasty effect of two (unkillable, even) Finder processes running, and Finder not working anymore at all. If this happens, logging out and back in again fixes it, but it's a waste of time obviously, so I use 'sleep'.
A sleep value of 0.5s works for me, but to be on the safe side, you can slightly increase it (adding a more noticeable delay to the process then).
If someone knows of a way to either suppress the Finder relaunch and unreliable opening of some window after sending the killall signal -- or some other way to get rid of the 'sleep' hack -- I'd be happy to hear it!