Recent Posts


Improving BBEdit’s “Go To Line”


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

After dropping it in one of my periodic feed purges, I recently re-followed the Brent Simmons authored weblog inessential after he posted a few articles on the sorry state of ad supported reading online.

Which is not what this post is about.

Brent recently wrote up a quick article on Mac OS X text application navigation as it compares to text navigation in every’s nerd’s favorite text editor, VIM. Specifically, he was bemoaning the lack of a consistent interface standard for the “Go To Line” line. In VIM this is as simple as typing a number and then hitting G while in command mode.

His criticism of my favorite editor (BBEdit) was that while the command existed, the dialog for it was a slower animating sheet instead of a quick acting dialog box. I was having trouble getting started today, so I figured a bit of quick AppleScripting would either exercise my coding muscles or make me appreciative of the more structured languages I pay the mortgage with.

set line_number to text returned of ¬
    (display dialog ¬
        "Line" with title ¬
        "Go To Line" default answer ¬
        "1" buttons {"Cancel", "Go To"} ¬
        default button 2 ¬
        with answer)

tell application "BBEdit" to tell window 1
    --set the text of window 1 to line_number
    if (line_number is "0") then
        set line_number to count lines
    end if
    --select line (line_number as integer)
    --select insertion point after (character (1) of line line_number)
    select insertion point before line (line_number as integer)
end tell

Open up the AppleScript Editor application, save this script to your BBEdit Scripts folder, and assign a keyboard shortcut and you’re good to go.

This doesn’t address every concern Brent had. The window is a larger than the normal Go To Line sheet, and there’s still the lack of standardization across editors, but it does display slightly faster than the default sheet and, more importably, got my coding muscles flowing this morning.

If anyone knows of a way to control the dialog size in AppleScript, please pass it on in the comments or directly.

Originally published November 28, 2011

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 28th November 2011

email hidden; JavaScript is required