How to make a script to show/hide hidden files in Mac OS X?

Viewed 18450

I just got my MBP with Retina and i'm really new to the Mac OS X (using PC before). I noticed that the Mac doesn't have a GUI to show/hide hidden files like Windows. I've researched and saw this site Show Hidden Files on your Mac. And yes, it works.

To show hidden files: (Using Terminal) defaults write com.apple.finder AppleShowAllFiles TRUE killall Finder

To hide hidden files: defaults write com.apple.finder AppleShowAllFiles FALSE killall Finder

What i wanted to do is to make an executable script that will perform the above commands when i double-click it so that i don't have to type commands in Terminal in order for me to show/hide hidden files. I saw Applescript but i'm not very familiar with it. I don't know the commands to perform what i want. But i've read some.

Can someone please help me make an executable script that will show/hide hidden files in my Mac?

9 Answers

Based on @user495470's answer...

In macOS Sierra (and likely before), you can throw this into the Run Apple Script box in automator instead:

do shell script "[[ $(defaults read com.apple.finder AppleShowAllFiles) = ON ]] && b=OFF || b=ON
defaults write com.apple.finder AppleShowAllFiles $b
killall Finder"

Line breaks matter (or else I would have just commented above).

killall Finder replaces the entire tell block as it will restart on its own when it is ready.

Related