AppleScript how to find pattern and set it to a re

2019-07-24 17:37发布

问题:

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