A: 

You're better off looking at MacScripter; there are lots of examples and solutions for find and replacing with or without a texteditor using Applescripts delimiters: MacScripter / Search results, like this:

on replaceText(find, replace, someText)
   set prevTIDs to text item delimiters of AppleScript
   set text item delimiters of AppleScript to find
   set someText to text items of someText
   set text item delimiters of AppleScript to replace
   set someText to "" & someText
   set text item delimiters of AppleScript to prevTIDs
   return someText
end replaceText
songdogtech
Thanks...looks like a good resource. I've updated my question to include some code that works part way...if you get a chance could you take a look and see if you can help?
Jason
Use sed in a shell script if you can; I use it in my own scripts for some find and replace, but Applescript can work, too.
songdogtech
+1  A: 

You'll have to send the keystroke to the proper window. Something like tell window "find dialog" (or whatever). You have to be completely specific, so it might be

tell tab 1 of pane 1 of window "find and replace" of app textmate... 

User interface scripting is so hackalicious you should only do it as a last resort.

Looks like you need sed.

on a command line, or with do shell script:

cat /path/to/your/file.php|sed "s_<?_<?php_g">/path/to/your/newfile.php

or for a whole folder's worth

cd /path/to/your/folder
for file in *.php; do  cat "$file"|sed "s_<?_<?php_g">"${file/.php/-new.php}"; done
stib
sed looks like it will fit my needs even better than applescript. Do you know if there is a problem with doing this: cat /path/to/your/file.php|sed "s_<?_<?php_g">/path/to/your/file.php from one file to the same file?
Jason
I think that will destroyinate the original file. What you can do is overwrite the original once sed has done its work using mv`for file in *.php; do cat "$file"|sed "s_<?_<?php_g">"${file/.php/-new.php}"; mv "${file/.php/-new.php}" "$file"; done`The mv command is moving file-new.php to file.php.
stib
NB: If this script is run twice it would turn your <?php tags into <?phpphp - sed is just replacing any <? with <?php. Better to use this in the sed part of the script:`sed "s_<?\(php\)*_<?php_g"`this looks for 0 or more "php" strings after the <? and overwrites them if they exist (=no change)
stib