Use Automator to quick edit "hosts" in Mac OS X
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:
- Open Automator
- In Library of Automator, choose "Get Specified Finder Items" in "Files & Folders" category. Drag it to the right panel.
- 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".
- 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.
- Click "Run" button on the top right to test it.
- 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!
July 3rd, 2009 at 6:53 am
No, it doesn't work in 10.5.7 on my MacBook Pro... Can you post the script?? Thanks!
July 4th, 2009 at 11:30 am
@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.