Toggle AppleShowAllFiles with a simple bash script?
Preface: I am a complete bash noob.
I want to write a simple script to toggle AppleSho开发者_StackOverflowwAllFiles 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.
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.
This should work for you:
if [[ $(defaults read com.apple.finder AppleShowAllFiles) == TRUE ]]
Show Hidden Files on your Mac
Launch the Terminal and enter these commands exactly as shown. The first command activates the ability to see the hidden files:
defaults write com.apple.Finder AppleShowAllFiles TRUE
Now you must relaunch the Finder by killing it, this is how the changes take effect:
killall Finder
精彩评论