Hi Guys,<br><br>First time poster, been using TM for a while though.<br><br>I'm
trying to write a command that will run, do it's thing, then save the
file.  The trick is how to get it to save AFTER the command alters the
file.  Is this possible?
<br><br>Specifically, what I am trying to do is update a `Last
Modified:` string whenever I save a file.  That's the easy part, I did
it with  some python triggered by cmd-s.  Now that the string has
been altered, how do I save the file?  It seems possible with
applescript, but I can't get it to work.
<br><br>If anyone has any suggestions about this final step, that
would be great.  I know there's something wrong with my applescript, it
tends to behave differently in osascript than in Script Editor, is this
because of the escaped quotes?  Something to do with combining triple- and single-quotes? <br><br>I've searched everywhere, apple documentation, textmate
wiki/mailing list, and turned up nothing!  It seems to me
that having a "Save After" option for Commands would be useful.  What
do you guys think? Maybe this has been discussed already.<br><br>Thanks for your help,<br>Jim Bagrow<span style="font-style: italic;"><span style="font-style: italic;"></span></span><br><br>Here is the command:<br>Save:  Current File
<br>Command:<br>******************************<div id="mb_0">*******************************
<br>#!/usr/bin/env python<br><br>import os<br>import re<br>import datetime<br><br># get selected text from shell:<br>path = os.getenv('TM_FILEPATH')<br>f = open(path, 'r')<br>text = f.read()<br>f.close()<br><br>string = "Last Modified: "+datetime.date.isoformat(
datetime.datetime.today() )<br>p = re.compile('Last Modified: \d\d\d\d-\d\d-\d\d')<br>result = p.sub(string, text)<br><br>print result<br><br># how can I save the file at this point, AFTER it's been modified?<br># PS: I hate applescript!
<br><br>cmd = """osascript -e \"<br>set thePath to do shell script \"echo $TM_FILEPATH\"<br><br>tell application \"TextMate\"<br>      activate<br>     save current document in thePath
<br>end tell<br>\"<br>"""<br><br>os.popen(cmd)<br>*************************************************************<br>Input: Entire Document<br>Output: Replace Document<br>Activation: Key Equivalent -> "cmd-S"
</div>