There are a lot of instructions on how to disable Java applets in different web browsers. However, none of the instructions I've seen have tackled my situation: in my home we each have one account, and even though I administer the computer I don't know the password of the other accounts hence I can't login as all the other users and manually uncheck the "Enable Java" check box in the Safari security preferences. Because of that I was looking for a way to do it automatically for all users, and this is what I came up with:
# become root
sudo -s
# exit all instances of Safari
killall Safari
# wait for Safari to exit
while ps axc|grep -q Safari ; do echo "waiting..." ; done
# for all users that have a Safari prefs file, set the appropriate keys to "false"
# paste the following all in one go
dscl . -list /Users home | while read username homedir ; do \
file="${homedir}/Library/Preferences/com.apple.Safari" ; \
if [ -f "${file}.plist" ] ; then echo "Disabling Safari's Java for user $username" ; \
for prop in com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled WebKitJavaEnabled ; do \
defaults write "$file" $prop false ; chown $username "${file}.plist" ; \
done; \
fi ; \
done
That's it!
Caveats:
- This will only change Safari's preferences (we use Safari at home, with Firefox reserved for sites that require Java or Flash)
- This will only change Safari's preferences if the user has launched Safari at least once
- While I have tested this in Mountain Lion (10.8.1) and Lion (10.7.4), I can't make any guarantees as to whether it'll work in your particular environment. Worst case it may reset your Safari preferences to default. Always have backups. :-)
If you want to disable all plug-ins as well as Java, something I recommend, run this instead for the last step:
dscl . -list /Users home | while read username homedir ; do \
file="${homedir}/Library/Preferences/com.apple.Safari" ; \
if [ -f "${file}.plist" ] ; then echo "Disabling Safari's Java and all plug-ins for user $username" ; \
for prop in com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled WebKitJavaEnabled \
WebKitPluginsEnabled com.apple.Safari.ContentPageGroupIdentifier.WebKit2PluginsEnabled ; do \
defaults write "$file" $prop false ; chown $username "${file}.plist" ; \
done; \
fi ; \
done