Wednesday, February 2, 2011

Reload the browser when files change on OSX

Web front-end development often looks like this, you change the code, which can be HTML, CSS, JavaScript, Ruby whatever and then you head over to the browser and reload it to see the changes.

This is not a big deal, but what if the browser could automatically does the reload.

My solution has three parts.
  1. You can detect file change with Kicker.

  2. Set the focus to the browser and reload it with AppleScript.

  3. Set the focus back to your texteditor.

Let's combine these

kicker -e "osascript reload-browser.applescript;focus-textmate.applescript" FOLDER_TO_WATCH

In my case this looks like this

kicker -e "osascript ~/workspace/MacGyver/reload-browser.applescript;osascript ~/workspace/MacGyver/focus-textmate.applescript" src/

You can find the reload_browser.applescript here and the focus-textmate.applescript here.

No comments:

Post a Comment