I'm very new to mac shell scripting, but I've written this to toggle hide/show hidden files on mac. (Then put on automator application) Is this a good solution?
#!/bin/sh
view=$(defaults read com.apple.finder AppleShowAllFiles)
if [ "$view" = "1" ]
then
defaults write com.apple.finder AppleShowAllFiles -bool false
else
defaults write com.apple.finder AppleShowAllFiles -bool true
fi
killall Finder
Instead of
killall Finder
, which is somewhat extreme and dangerous (you may kill the Finder in the middle of file copying or other I/O operations). Instead you could just send an AppleEvent to the Finder to tell it to refresh a given window. E.g. to refresh the frontmost window you can do this in AppleScript:(from http://hints.macworld.com/article.php?story=2009091413423819)
You can easily adapt this to refresh every open Finder window if that's what you need.
To run AppleScript code such as the above from a bash script you can use the osascript command line tool, e.g.