TextWrangler: Preview in Web Browser Script


IT Cocktail:
OS X Ingredients


TextWrangler Logo Setting up TextWrangler for CIT Web Dev

(The following script is from Preview in Browser script for TextWrangler, by Mike Piontek.)

TextWrangle does not include a Preview in Web Browser command, but we can add that command using AppleScript.

  1. Open Script Editor (in your Applications/AppleScript folder).

  2. Paste this text into a new script:

    tell application "TextWrangler" to set theFile to file of document 1
    tell application "Finder" to open theFile using (path to application "Firefox")


  3. You can change “Firefox” to the exact name of any browser you like (Safari, Opera, Chrome, etc.). You could even repeat that line several times with different browser names to open the file in all of your browsers at once.

  4. Save the file to your home folder/Library/Application Support/TextWrangler/Scripts/. You can name the script anything you want, e.g., "Preview in Web Browser."

  5. Start TextWrangler. You will see the script in TextWrangler’s script menu. The script menu has an icon that looks like a scroll of parchment.

Now all you have to do to preview the current document is select that command from the script menu! Even better, you can assign it a keyboard shortcut:

  1. In TextWrangler, open the Window menu, go down to Palettes, and then select Scripts. The Script palette will open.

  2. Select your script in the Script palette, and click the “Set Key” button.

  3. Enter the key command you want.

NOTE: When you select the Preview in Web Browser command in TextWrangler, a new FireFox window will open, displaying your web page. If you make any changes to the .html file, just hit the Reload button in that browser window to see the changes-- you do not have to repeat the Preview in Web Browser command.