Posted on 04-02-2013 10:26 AM
Goal : Create a script to hide hidden files to be delivered by a policy
Attempt: Created a text files and entered the following
defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
Renamed to .sh
Does not seem to take. What am I missing?
Posted on 04-02-2013 10:43 AM
I'm guessing the hidden flag needs to be reapplied to the files. Man chflags and that should get you in the right direction.
Posted on 04-02-2013 10:46 AM
#!/bin/sh
CurrentUser=`who | grep "console" | awk '{print $1}'`
sudo -u $CurrentUser defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder
This is the script I wrote for this I think you need to do it per user as the script is run as root. Ours is in self service for certain people, but if you set it as a log in policy it should work.
Posted on 04-02-2013 11:25 AM
rlandgraf: Thanks for the script. Works great for Self-Service and through a policy. The drawback as you described is that it only work on the current user instead of the computer as a whole. Anybody have a thought on how to perform the latter?
Posted on 04-02-2013 01:29 PM
Just change it to point at the root /Library/Preferences/ folder:
#!/bin/sh
defaults write /Library/Preferences/com.apple.finder AppleShowAllFiles FALSE
killall Finder
Although the com.apple.finder.plist file doesn't exist normally in the /Library/Preferences/ path, the above command creates a new one with that single setting in it. As long as its running as root, it will be able to create the file.
If you don't specify a proper path, just using "com.apple.finder" (or whatever plist you're trying to write to) will only apply to the account actually running the command. In the case of a Casper Suite policy, that would be root. If you do it as yourself while logged in, it looks to the file located at ~/Library/Preferences/
I'm not 100% certain if the above command pointed at /Library/Preferences/ then applies to all accounts, but in my tests, restarting Finder will show me invisibles if you change the above to "TRUE"
Last thing to keep in mind is that, unless you convert the above into either a System Level Enforced MCX or put it into a profile, an individual user's com.apple.finder.plist can potentially contain an AppleShowAllFiles TRUE setting that would override the above "FALSE" one you've placed in the root /Library/Preferences/ folder. If there is no setting in their plist, it uses the one in the above location, otherwise, it will use whatever is in their local plist.
Does that make sense?
Posted on 05-15-2014 10:07 AM
If anyone is interested I used those commands to create a script to toggle hidden files from Self Service:
#!/bin/bash
CurrentUser=`who | grep "console" | awk '{print $1}'`
STATUS=`sudo -u $CurrentUser defaults read com.apple.finder AppleShowAllFiles`
if [ $STATUS == TRUE ];
then
sudo -u $CurrentUser defaults write com.apple.finder AppleShowAllFiles FALSE
else
sudo -u $CurrentUser defaults write com.apple.finder AppleShowAllFiles TRUE
fi
killall Finder