AppleScript how to find pattern and set it to a record or list?

别来无恙 提交于 2019-12-11 06:55:05

问题


In AppleScript I know how to do a typical find with something like:

tell application "BBEdit"
    activate
    open find window
    find "memberFunction\\(\\)" searching in text 1 of text document "theFile" options {search mode:grep, wrap around:true} with selecting match
end tell

and I can do a multi file search find:

tell application "BBEdit"
    activate
    find "memberFunction\\(\\)" searching in {file "path:to:project.bbprojectd:"} options {search mode:grep, showing results:true}
end tell

but I'd like to return the find multi result and save it to a file so I thought I'd need to save it to a record or list then repeat through the input but when I try:

tell application "BBEdit"
    activate
    set findFunction to {}
    set findFunction to {find "memberFunction\\(\\)" searching in {file "path:to:project.bbprojectd:"} options {search mode:grep, showing results:true}} as list
end tell

or:

set findFunction to {find "memberFunction\\(\\)" searching in {file "path:to:project.bbprojectd:"} options {search mode:grep, showing results:true}} as record

I get an error of:

No result was returned from some part of this expression.

Why is the find not being set to the record or list? Is there a way I can set what the multi-file search does?


回答1:


The error is that you put the find command in a list.


To get a record from the find command:

The showing results property must be false and the returning results property must be true, otherwise the findFunction variable will be undefined

Here's the script:

tell application "BBEdit"
    set findFunction to find "memberFunction\\(\\)" searching in file "path:to:project.bbprojectd:" options {search mode:grep, showing results:false, returning results:true}
end tell


来源:https://stackoverflow.com/questions/43550034/applescript-how-to-find-pattern-and-set-it-to-a-record-or-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!