Is there a way to replace text within a selection using Applescript for BBEdit? I have a replace script, and I'd like to run it for only selected text. I know you can replace in selection using the find menu, but I can't find anything that says it does this in the AppleScript dictionary for BBEdit. Thanks.
To use an application's scripting dictionary, specific commands aren't necessarily declared, just their syntax and options. Usually you can look at a command to see what the parameters are, which also defines the data types that it is expecting - in this case for example, the replace
command has a searching in
parameter, which can be anything.
The answer is similar to the one to your other topic, you just need to further define where to search. For example, the selection
is a property of a window
, and a window
is a property of a document
:
tell application "BBEdit"
tell front document
replace "12:" using "{#pl}:" searching in its window's selection
end tell
end tell