@apple4us typical "wolf's coming" for the gov has done 2 much evil. Hard 2 believe not related 2 them. Haha.

Use Automator to quick edit "hosts" in Mac OS X

May 24th, 2009 by Tkjune

A web developer often edit hosts file for developing use. In windows, you can create a shortcut to use notepad to open and edit the hosts file. In Mac OS X, I like using Spotlight to quick open the stuffs I want. But the hosts files is hidden by default and can not be found in Spotlight. So I use Automator to triger TextMate to open hosts file for editing.

Here's what I did in Mac OS X 10.5.6:

  1. Open Automator
  2. In Library of Automator, choose "Get Specified Finder Items" in "Files & Folders" category. Drag it to the right panel.
  3. Open Finder, select "Go -> Go to Folder..." from menu (or use shortcut key "CMD+SHIFT+G"), input "/private/etc/". You can find "hosts" file here. Drag it to Automator, the file list area in "Get Specified Finder Items".
  4. In Library of Automator, choose "Open Finder Items" in "Files & Folders" category. Drag it to the right panel. Choose the application you like to open the hosts file. As to me, I chose TextMate.
  5. Click "Run" button on the top right to test it.
  6. Save it as application in "Application" folder.

This works alright in 10.5.6. But I just upgrade to 10.5.7 a few days ago and I found that it does not work. When test run, the automator can find out the file but cannot open it, even after I repairing the disk permissions. Then I changed another way for step 4 here:

4. In Library of Automator, choose "Run AppleScript" in "Utilities" category. Input following lines:

on run {input, parameters}
tell application "TextMate"
open input
end tell
return input
end run

Test run and bingo!

5 Responses to “Use Automator to quick edit "hosts" in Mac OS X”

  1. Jorge Says:

    No, it doesn't work in 10.5.7 on my MacBook Pro... Can you post the script?? Thanks!

  2. Tkjune Says:

    @Jorge: The scripts are above lines
    on run {input, parameters}
    tell application "TextMate"
    open input
    end tell
    return input
    end run
    I've been experienced the failure in 10.5.7, that's why I used the AppleScript.

  3. hot trends Says:

    I feel a lot more people need to read this, very good info! . . . . . .

  4. ds Says:

    was trying to do this via a shell script like so...

    #!/bin/bash
    sudo vim /private/etc/hosts

    but was getting annoyed with it. Your steps worked for me right off the bat. Many thanks.

  5. Tkjune Says:

    @ds I'm always so happy of providing some helpful tip :) enjoy.

Leave a Reply