AppleScript to Edit hosts File?
I edit my hosts file a lot, and I am trying to edit it with one click, or something similar. I found an Automator application that would modify the hosts file and open it to show the modifications. It worked once, but now I've re-downloaded it to try to change it in Automator. I found this in Automator:
Run AppleScript:
on run {input, parameters}
set hostToAdd to "echo '
# Block Adobe Activation
127.0.0.1 (A bunch of hostnames that would be pointless to share)
' >>"
set fileHosts to "/etc/hosts"
do shell script hostToAdd & fileHosts with adminstrator privileges
return input
end run
Get Specified Finder Items
hosts
Open Finder Items
Then, I modified the script to this:
set x to text returned of (display dialog "What do you want to add?" default answer "127.0.0.1 ")
set hostToAdd to "echo '
keystoke x
' >>"
set fileHosts to "/etc/hosts"
do shell scripthostToAdd & fileHosts with administrator privileges
return input
end run
it asked me what I wanted to add, asked for my password, opened my hosts, but nothing was changed. The original app didn't change anything either anymore.
Any advice? What do I need to change? Is it because I ran the original application previously?
Thanks for your help
MacBook Pro, OS X Mountain Lion (10.8.2)