Run a script on save in textmate

3

1

I was wondering if it was possible to run a custom script on save based on certain file names in textmate. For example I'd like to auto compile a C program sometime on save.

Matt

Posted 2009-12-21T08:19:13.310

Reputation:

Answers

4

It's actually fairly easy to do this using a custom command in a bundle.

Here's how to make a simple command:

  • Open up the bundle editor, and find the bundle you want to add to.
  • Create a "New Command" using the button on the bottom left of the editor. Name it appropriately, and set its scope to source.c.
  • Set the action dropdown to "Key Equivalent", and set the shortcut Cmd + S.
  • Change the "Save" dropdown to "Current File".
  • Enter your command, and set the input and output dropdowns appropriately. Input will be piped to STDIN if I remember correctly.
  • Reload TextMate's bundles.

That's it. You should now have a command which saves the file, and runs a command.

You can probably do something with TextMate commands by using a macro in a similar way.

Matt

Posted 2009-12-21T08:19:13.310

Reputation: 171

1

you can trigger a command after save via callback.document.did-save semantic class. This works on TextMate2+

vigo

Posted 2009-12-21T08:19:13.310

Reputation: 291

Where does the semantic class can be added ? It can be useful when the save happens automatically and not by a key press. – challet – 2020-01-10T10:36:27.790

Found it : that is one of the input of a command form. – challet – 2020-01-10T10:49:06.677

1

As far as I know, there's no way to do this as you described, for all save situations (i.e., using Command-S, selecting File->Save, etc.).

You might be able to create a custom bundle item that saves the document and executes your script, and assign it Command-S, so that it runs when you use that keyboard shortcut.

Lawrence Velázquez

Posted 2009-12-21T08:19:13.310

Reputation: 929