I’m looking to create aAppleScript that when run will:
- Search the document for a given string
- Replace that string with another given string
The strings will always be the same
Search for
This will be used in textmate – I was trying to do this in textmate
I know I can use textmate’s find and replace functionality – I’m just trying to automate a little.
This should only make changes on the current page.
Is this possible?
UPDATE:
So I’ve found some code that has got me started…
tell application "TextMate" to activate
tell application "System Events"
keystroke "f" using {command down}
tell process "TextMate"
keystroke "<?"
keystroke tab
keystroke "<?php"
click button "Replace All"
end tell
keystroke "esc"
end tell
but I get the following error:
error "System Events got an error: Can’t get button \"Replace All\" of process \"TextMate\"." number -1728 from button "Replace All" of process "TextMate"
On the find and replace dialog of Textmate the button is labeled “Replace All” Am I missing something here?
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 beUser 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:or for a whole folder’s worth