简体   繁体   English

如何在选择中使用 AppleScript 替换 BBEdit?

[英]How to replace in selection using AppleScript for BBEdit?

Is there a way to replace text within a selection using Applescript for BBEdit?有没有办法使用 Applescript 为 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.我知道您可以使用查找菜单替换选择,但我在 BBEdit 的 AppleScript 字典中找不到任何说明它这样做的东西。 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.通常您可以查看命令以查看参数是什么,它还定义了它所期望的数据类型 - 例如,在这种情况下, replace命令有一个searching in参数,可以是任何参数。

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 :例如, selectionwindow的属性,而windowdocument的属性:

tell application "BBEdit"
   tell front document
      replace "12:" using "{#pl}:" searching in its window's selection
   end tell
end tell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM