Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle AppleShowAllFiles with a simple bash script?

Preface: I am a complete bash noob.

I want to write a simple script to toggle AppleShowAllFiles on my mac.

I am thinking something like this:

#!/bin/bash
#toggle AppleShowAllFiles

if defaults read com.apple.finder AppleShowAllFiles == TRUE
then
  defaults write com.apple.finder AppleShowAllFiles FALSE
else 
  defaults write com.apple.finder AppleShowAllFiles TRUE
fi

killall Finder

That doesn't seem to be working, but I am sure one of you could bash it out in 1 second flat; please commence bashing and help a lost soul!

thanks.

like image 901
James Avatar asked Mar 22 '26 17:03

James


1 Answers

Here is a fixed version of your script:

#!/bin/bash
#toggle AppleShowAllFiles

current_value=$(defaults read com.apple.finder AppleShowAllFiles)
if [ $current_value = "TRUE" ]
then
  defaults write com.apple.finder AppleShowAllFiles FALSE
else
  defaults write com.apple.finder AppleShowAllFiles TRUE
fi

killall Finder

The if syntax of your script was a bit...well, iffy. That's all that needed to be changed.

like image 188
Carter Allen Avatar answered Mar 25 '26 11:03

Carter Allen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!