champak256
champak256

Reputation: 115

How do I use a command in an if statement in a Terminal Script on mac?

I am trying to write a script that will toggle between showing and hiding hidden files in Finder, but I'm having trouble with an error:

./HiddenFileToggle: line 1: [defaults: command not found

if [defaults read com.apple.finder AppleShowAllFiles]
then
defaults write com.apple.finder AppleShowAllFiles TRUE
else
defaults write com.apple.finder AppleShowAllFiles FALSE
fi
killall Finder

Upvotes: 2

Views: 1838

Answers (1)

kiplantt
kiplantt

Reputation: 323

Enclose the command in backticks `:

`defaults read com.apple.finder AppleShowAllFiles`

Upvotes: 2

Related Questions