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

link|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 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 at 9:05
feedback

2 Answers

#!/bin/bash

trap 'exit 0' EXIT
k="com.apple.Finder AppleShowAllFiles"
read="`defaults read $k 2>&1 /dev/null`"
[[ "$read" == true || "$read" == 1 || "$read" == yes ]] && b=false || b=true
defaults write $k -bool $b
osascript -e 'try
quit app "Finder"
end
delay 0.1
tell app "Finder"
launch
delay 0.2
activate
end'
link|improve this answer
feedback

AppleScript or a shell script?

Of course I like the widget best.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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