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

The Future of Deliveries Deliveries began as a hobby—it was first released as a Dashboard widget named “Apple…

An update on our apps It’s been a while since we shared an update on everything we’re working on. With iOS 15…

Upcoming changes to Deliveries Deliveries 9.2 will be available soon, and we wanted to let you know about some changes…

Deliveries 9 will arrive September 30 Deliveries 9 will be available this Wednesday, September 30, for iPhone, iPad, Apple…