I think there are a couple problems with your script. Perhaps you've
only sent part of a longer script, so forgive me if we're missing part
of the picture. However:

1.  First, that error disappeared when I removed the "tell text
document 1" statement. I don't think you have to tell text document 1
anything; the replace command specifies text 1 of text document 1 as
its target. Plus it seems to fubar something, although I didn't
understand exactly why.

That gives us the following, which doesn't work but doesn't throw
errors (I commented out the guilty tell statement, and also commented
out stuff that wasn't defined or necessary to the test, Plus I had to
add arbitrary value for mod_date):

>
> tell application "BBEdit"
> activate
> -- open j opening in new_window
> -- tell text document 1
> -- activate
>
> -- define mod_date
> set mod_date to 29
>
>
> set searchStr to "2007-08-\\d\\d"
> set replaceStr to "<!--MODDATE-->" & mod_date & "<!--\\/MODDATE-->"
>
> replace (searchStr as string) using (replaceStr as string) options {search 
> mode:literal, starting at top:true} searching in text 1 of text window 1
> -- save text window 1
>
> -- close window 1
> -- end tell
> end tell
>

2. You're trying to use grep, so you do need to give that as your search mode

3. I think you want to wrap the full date with those MODDATE tags, but
mod_date is an undefined variable.

4. When "&" appears in the replacement field while using grep, "&"
means "the full pattern from the find field". In this case "&" = the
full date that matches searchStr.  If you want an ampersand, you must
escape it:  \& or, in AppleScript, \\&
   Anyway, you don't need those ampersands here. You don't want
AppleScript to join this text together; you want AppleScript to pass
along a regular expression replacement pattern.

5. It's not consequential, but I don't think you need the two
backslashes in "<!--\\/MODDATE-->"

Solution:
  Your search pattern is good
  Your replacement pattern should be: "<!--MODDATE-->&<!--\\/MODDATE
-->"
That single ampersand means "the recognized date" so you should wind up with
<!--MODDATE-->2007-08-29<!--\\/MODDATE-->
(or whatever day)

The following works for me:

> tell application "BBEdit"
>
>     activate
>
>     set searchStr to "2007-08-\\d\\d"
>     set replaceStr to "<!--MODDATE-->&<!--/MODDATE-->"
>     replace (searchStr as string) using (replaceStr as string) options 
> {search mode:grep, starting at top:true} searching in text 1 of text window 1
>
> end tell
>

hope that helps,
CC

-- 
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to