Preview in Browser script for TextWrangler

There are a lot of great text editors out there for OS X, but I’d have to say TextWrangler is the best out of the few that are totally free. Personally I can’t live without its big brother BBEdit, but with the $125 entry fee, I can understand why a lot of people are more than happy to stick with TextWrangler. It is missing a lot of features that BBEdit has, but the good news is you can expand it quite a bit using AppleScript. Here’s a quick and easy example, for previewing the current HTML page in a browser.

  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 "Safari")
  3. You can change “Safari” to the exact name of any browser you like. 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/
  5. You should see the script in TextWrangler’s script menu now. 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.

Update: A couple of notes on this for anyone having troubles: first, you need to make sure your document is saved before you preview it. Also, make sure the script is entered exactly as shown above. The “path to application” is an instruction for AppleScript to get the path—not an instruction for you to enter it!

Comments

This entry has 2 comments.

Jan

Jan wrote on October 21, 2006:

Very useful, thank you for the script!

Ryan

Ryan wrote on November 3, 2006:

Very useful, thanks so much! Designing a new eBay template layout and this makes it a lot easier. Keep up the good work.

View more

Mac OS X

Deliveries: now with dark mode and support for the latest devices This week we released Deliveries 3.1 for Mac, with support for macOS Mojave’s new dark…

Compatibility with iOS 12, watchOS 5, and macOS Mojave iOS 12 and watchOS 5 are available now, and macOS Mojave will be out soon. For the most…

Improvements to Junecloud Sync We recently gave Junecloud Sync a significant update. Most of the changes are behind…

Improved iCloud syncing in our apps We’ve completely redone iCloud syncing in our apps to make it faster and more reliable…