Skip to content

Instantly share code, notes, and snippets.

@raoulwegat
Created November 25, 2012 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raoulwegat/4142864 to your computer and use it in GitHub Desktop.
Save raoulwegat/4142864 to your computer and use it in GitHub Desktop.
OS X service to add folder name to localhost DNS
This is my workaround to an otherwise automated Apache/vhost + dnsmasq +/etc/resolver/dev setup that fails when I'm offline and my local sites are unreachable. After I create a folder under ~/Sites, I now right-click > Services > Add Site to DNS and my sites are available offline. It's sudo vi /etc/hosts workaround.
To cleanup/maintain, use the dscl commands from here:
http://tomafro.net/2009/07/dscl-the-easy-way-to-add-hosts-on-osx
tell application "Finder"
set theItems to selection
set folderName to name of item 1 of theItems
do shell script "sudo dscl localhost -create /Local/Default/Hosts/" & folderName & ".dev IPAddress 127.0.0.1"
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment