Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

In pseudocode:

if can view hidden files

set com.apple.Finder AppleShowAllFiles false

else

set com.apple.Finder 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
1  
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

2 Answers 2

#!/bin/bash

k="com.apple.Finder 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"
quit
delay 0.2
launch
activate
end'

Or an AppleScript version:

set k to "com.apple.finder 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"
    quit
    delay 0.2
    launch
    delay 0.2
    activate
end tell
share|improve this answer

AppleScript or a shell script?

Of course I like the widget best.

share|improve this answer

Your Answer

 
discard

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.