Script to edit Hosts File

tschwartz
New Contributor

Does anyone have a script to edit the Hosts file that they'd be willing to share? We need to add an entry to enforce Google Safe Search.

1 REPLY 1

RobertBasil
Contributor

Here is part of an automator script I use to block a few sites:

do shell script "echo '#' > /private/etc/hosts" with administrator privileges do shell script "echo '#' Host Database >> /private/etc/hosts" with administrator privileges do shell script "echo '#' >> /private/etc/hosts" with administrator privileges do shell script "echo '#' localhost is used to configure the loopback interface >> /private/etc/hosts" with administrator privileges do shell script "echo '#' when the system is booting. Do not change this entry. >> /private/etc/hosts" with administrator privileges do shell script "echo '#' >> /private/etc/hosts" with administrator privileges do shell script "echo 127.0.0.1 localhost >> /private/etc/hosts" with administrator privileges do shell script "echo 255.255.255.255 broadcasthost >> /private/etc/hosts" with administrator privileges do shell script "echo ::1 localhost >> /private/etc/hosts" with administrator privileges do shell script "echo 127.0.0.1 itunes.apple.com >> /private/etc/hosts" with administrator privileges do shell script "echo 127.0.0.1 youtube.com >> /private/etc/hosts" with administrator privileges do shell script "echo 127.0.0.1 www.youtube.com >> /private/etc/hosts" with administrator privileges do shell script "echo 127.0.0.1 m.youtube.com >> /private/etc/hosts" with administrator privileges do shell script "killall -HUP mDNSResponder" with administrator privileges