Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to always run the same file in TextMate, when working on a Python project? I always press +R when editing a random file, forgetting to switch back to the tab containing the main of this project. There's got to be a way to do that; clicking tabs is really a speed-bump in that scenario.

share|improve this question
To shorten that speed bump slightly, perhaps keep the main file as the first tab, then quickly jump to it before running your script with ⌘1 before hitting ⌘R. Combined, it's pretty fast. However, I wouldn't mind a solution to this myself. Sort of like %!TEX root for TeX files in TextMate and TeXShop. – fideli Aug 22 '10 at 5:20
up vote 2 down vote accepted

Yes it is possible and there are several possibilities to achieve that. An easy fix would be to write a command which invokes python on the main file, i.e.

python /path/to/project/

as a command bound to Command + R. Better commands would be




However, you will loose the nice looking output the default command provides. Therefore you have another option: Set the instance variable $TM_PROJECT_MASTER to point to your main file. You can either set this variable absolute or relative to $TM_PROJECT_PATH. A relative path may be advisable of course. To do so, you may either set $TM_PROJECT_MASTER as a static environment variable, which can be done as follows

  1. Go to "Settings" > "Advanced" > "Shell Variables"
  2. Add the variable "$TM_PROJECT_MASTER" and type in "" or whatever is appropriate for your projects

If the location of your main file changes from project to project, this setting doesn't help. However, you can set project dependent shell variables, which would be the solution in such cases:

  1. deselect alls files in your project drawer
  2. click the small info button - a window with project dependent shell variables will pop up
  3. again add the variable "$TM_PROJECT_MASTER" and fill in the relative position of your main file

This should help. Have fun!

PS: See if you look for an explanation, why setting $TM_PROJECT_MASTER helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.