Haxin Mainframes

A blog about stuff I do, find interesting, or want to blab about..

Open File From Console Python Traceback in Text Editor

Often when I am programming I want to be able to quickly find a function/class definition when I hit a traceback. My normal dev environment is basically just Sublime Text 2 and the OSX console. My Co-Worker Brahm Cohan figured out a cool trick the other day from one of his friends I believe.

Basically, you:

Open, the Automator app. Create a new “Service”.

Service Project in Automator

The service should execute the following (you can replace Sublime with whatever editor you use):

open -a Sublime\ Text\ 2 $1

Sublime Text command

Then open up System Preferences. Goto Keyboard under the Keyboard Shortcuts menu scroll down to find your new service. I named mine tosublime and set the Command-L combo to run it.

Perferences Keyboard window

Now I can select the absolute path of a file in my python tracebacks and hit Command L. This opens up the file I need to start debugging in. With a little more work I am sure you could parse out the line number too.