Artificial intelligent assistant

Bash script to hide/show files I prepared a little bash script to toggle the visibility of my hidden OS X files. if (defaults write com.apple.finder AppleShowAllFiles FALSE); then defaults write com.apple.finder AppleShowAllFiles TRUE elif (defaults write com.apple.finder AppleShowAllFiles TRUE); then defaults write com.apple.finder AppleShowAllFiles FALSE fi killall Finder When hidden files are invisible, the script successfully makes them visible but afterwards, when I re-run the script to make the hidden files invisible again, it fails and does nothing. Where am I going wrong?

In the `if` conditions you should use the `defaults read` command, and not `write`. Otherwise the result is always true and of course the `elif` never runs.

Also, that is not the syntax for `if` conditions. You should use:


if [ $(command) == "TRUE" ]; then


But in this case, perhaps something like this would be less verbose:


STATUS=$(defaults read com.apple.finder AppleShowAllFiles)
case "$STATUS" in
"TRUE") OPTION="FALSE" ;;
"FALSE") OPTION="TRUE" ;;
esac
defaults write com.apple.finder AppleShowAllFiles $OPTION

killall Finder

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a74f15070912a73b60829f07bc4f8b7c