Switch AppleShowAllFiles with a simple bash script?

Foreword: I am a complete bash noob.

I want to write a simple script to switch AppleShowAllFiles to my mac.

I think 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

This does not work, but I am sure that one of you could bash exit in 1 second; start beating and helping a lost soul!

thank.

+3
source share
3 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 syntax of ifyour script was a bit ... well, iffy. That was all that needed to be changed.

+3
source

This should work for you:

if [[ $(defaults read com.apple.finder AppleShowAllFiles) == TRUE ]]
+3
source

Mac

, . :

defaults write com.apple.Finder AppleShowAllFiles TRUE

Finder, , :

killall Finder

0

Source: https://habr.com/ru/post/1796533/


All Articles