CC:
It works! Thanks very much!
All I needed to do was comment out the "tell text document 1" lines
and it started working just the way it should.
It was indeed a snippet of a larger script, which is why mod_date
wasn't defined.
Re your point #4--the ampersands were there to concatenate
AppleScript strings, not to insert the found text, but thanks for the
tip about the & in the replacement string--I didn't know that and I'm
sure it'll come in handy in the future.
What I'm actually trying to do with this script is replace the hard-
coded modified date for the file with the ACTUAL modified date. I
have code earlier in the script that grabs the actual date from each
file.
Thanks again to everyone for their helps and suggestions,
Ian
On Nov 9, 2007, at 11:35 AM, Complex wrote:
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]>
Ian Crew
Supervisor, Collaboration Services
Information Services and Technology-Data Services
University of California, Berkeley
2195 Hearst Ave, Second Floor
http://ist.berkeley.edu/ds/
2009 Chair, Chancellor's Staff Advisory Committee
http://csac.chance.berkeley.edu
--
------------------------------------------------------------------
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]>