On Sep 29, 2009, at 3:36 AM, dannyg wrote:

> I've had a script doing fine here for years until I did a double
> upgrade of BBEdit (from 7.x to the current version) and Leopard to
> Snow Leopard. I don't know which upgrade is causing the issue I'm
> having, and the fact that I can't view the BBEdit dictionary in Snow
> Leopard's Script Editor limits my exploration.

This is a bug in the AppleScript Editor on 10.6. We have reported it  
to Apple and are working with them to resolve it.

> The issue is that my script opens a local file and then invokes the
> replace command (with options returning results) so that I can get a
> count of the instances of a particular string within the document.
> Here is a sample:
>
> set deletedData to replace "frobnitz" using "frobnitz" searching in
> {text 1 of text window "log.1"} ¬
>                       options {starting at top:true, returning results:true}

That sounds like the wrong hammer for this particular problem...

> After each such replace command, the script now halts while a BBEdit
> dialog appears, asking whether to save before continuing. I perform
> multiple replaces within the same document and get a dialog for each
> replace command invocation (i.e., it's not happening upon closing the
> document). Is there some newer, extra parameter I can send to bypass
> this dialog?

The reason that you are getting the prompt is that you are putting the  
replace command into batch mode by passing a list, instead of a single  
specifier, as the value for the "searching in" parameter.

Pass a single specifier, and it will just do the work without the  
prompt.

There is also a saving parameter (whose values can be yes, no, ask) to  
control the behavior in "batch" mode. The default is ask.

> Or perhaps there is a more recent command that lets me get the  
> counts I need.

Replacing "frobnitz" with "frobnitz" to count the instances of  
"frobnitz" has a certain code smell to it. (And it does do real work  
under the hood, creates an undo state, etc.)

Independent of any issue above, you are probably better of writing  
something like this:

tell application "BBEdit"
        set results to find "frobnitz" searching in {text 1 of text window 1}  
options {starting at top:true, returning results:true}
        set instanceCount to 0
        if found of results then
                set instanceCount to length of found matches of results
        end if
end tell
display alert (instanceCount as string)

Note that in the current release there is a limitation which requires  
that the document not be untitled in order to get back the batch find  
results. This was recently discussed here.

Hope this helps,
Jim


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---

Reply via email to