Automator macOS – How to Show/Hide Hidden Files

automatormacos

I'm still running El Capitan so I don't have that shortcut for show/hide hidden files. A while ago I've created automator service, which using the keyboard shortcut could show/hide hidden file depending on previous state. I've clean installed the os and decided to recreate what I did before, and I am stuck on getting if [ Commandresult = State ]; then part to work.

#!/bin/sh
if [ defaults read com.apple.finder AppleShowAllFiles = "FALSE" ] 
then
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
else 
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
fi

I've seen Show/Hide hidden files without restarting finder?, but I know it could be shorter like this since I had it working with something like this before.

Best Answer

Your if statement test,[ ... ], is not properly formed, change:

if [ defaults read com.apple.finder AppleShowAllFiles = "FALSE" ]

To:

if [ "$(defaults read com.apple.finder AppleShowAllFiles)" = "FALSE" ]