Re: find/replace in BBEdit
Re: find/replace in BBEdit
- Subject: Re: find/replace in BBEdit
- From: "Christopher C. Stone" <email@hidden>
- Date: Mon, 11 Dec 2000 05:54:29 -0600
At 12/10/00 22:20 -0600, Rick Plummer wrought:
>
I need to open a file (BBEdit will open it) and replace a string in one line with a reference pulled from Applescript, then resave the file with the original type and creator. I have tried, but I'm afraid it's way beyond me.
___________________________________________________________________________
Hey Rick,
BBEdit does *not* change the existing type and creator codes of files upon saving as some other editors do.
This is for BBEdit 6 and should give you an idea or two:
set bbeDoc to "goofyTestFile.bbe"
set findText to "two"
set replaceText to "* between one and three"
tell application "Finder"
set bbeDoc to (make file at desktop with properties {name:bbeDoc}) as alias
end tell
set txt to "one" & return & "two" & return & "three"
try
set f to open for access bbeDoc with write permission
write txt to f
close access f
on error
close access f
beep 2
end try
tell application "BBEdit"
activate
open bbeDoc with properties {position:{5, 41}}
delay 1
tell front text window
replace findText using replaceText options {starting at top:true}
select line 2
delay 1
select insertion point before line 2
delay 1
save
close
end tell
end tell
tell application "Finder"
open bbeDoc
end tell
Best Regards,
Chris