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.

if [ defaults read com.apple.finder AppleShowAllFiles = "FALSE" ] 
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder

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.

  • The reason it fails in a clean install is because the AppleShowAllFiles key does not exist in the com.apple.finder plist file. You can quickly solve the issue by executing the following compound command in Terminal: defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder Otherwise, you'll need to write the if statement to handle the fact that the defaults command is not returning the expected boolean. – user3439894 Feb 16 '19 at 4:20
  • @user3439894 I have ran those commands in sh, and do you have any idea why defaults read com.apple.finder AppleShowAllFiles = "FALSE" always return FALSE regardless of what AppleShowAllFiles boolean is. It is the same problem when I remove double quotation from FALSE in command. – user321280 Feb 16 '19 at 4:41
  • 2
    Change if [ defaults read com.apple.finder AppleShowAllFiles = "FALSE" ] to: if [ "$(defaults read com.apple.finder AppleShowAllFiles)" = "FALSE" ] – user3439894 Feb 16 '19 at 4:58
  • @user3439894 Thank you so much, it now works perfectly – user321280 Feb 16 '19 at 5:02
  • The is also a way to Show/Hide files from menu bar. The automator service can be downloaded from Toggle Hidden Files. When installed, you can select Finder->Services->Toggle Hidden Files from the menu bar. – David Anderson Feb 16 '19 at 11:53

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

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


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

You must log in to answer this question.