Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to toggle the hidden files visibility on/off with a terminal script?

In pseudocode:

if can view hidden files

set AppleShowAllFiles false


set AppleShowAllFiles true

killall Finder

share|improve this question
To be clear, you would like to use a Terminal/shell script to control hidden file visibility in the Finder, correct? If so, please clarify your question. – fideli Jan 17 '12 at 1:48
Note that in Open File dialogs, you can show hidden files using Cmd-Shift-.. In many cases, this should be good enough. – Daniel Beck Jan 17 '12 at 9:05
@DanielBeck that trick is extremely useful. thank you – rabbid Aug 27 '12 at 23:53

k=" AppleShowAllFiles"
b=$(defaults read $k 2>&1 /dev/null)
[[ "$b" == 1 ]] && b=false || b=true
defaults write $k -bool $b
osascript -e 'tell app "Finder"
delay 0.2

Or an AppleScript version:

set k to " AppleShowAllFiles"
set r to do shell script "defaults read " & k
do shell script "defaults write " & k & " -bool " & (r is 0 as text)
tell application "Finder"
    delay 0.2
    delay 0.2
end tell
share|improve this answer

AppleScript or a shell script?

Of course I like the widget best.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.