Copy link to clipboard
Copied
Hello. I have a trouble with grep search. When searching manually it works, but when i try to use js script it applyes only the last pattern from three. I do not understand why.
I mean:
"app.findTextPreferences" ==> "app.findGrepPreferences"
"app.changeTextPreferences" ==> "app.changeGrepPreferences"
[I've not checked your patterns!]
(^/)
Copy link to clipboard
Copied
Hi @Viktoriia_ you haven't given us enough code to actually run it (there are two functions missing) but hopefully this will give you an idea of what's missing:
// Define patterns to apply the character style
var patterns = [
"\\<[^[:space:]]+://[^[:space:]]*\\>",
"\\<[^[:space:]]+@[^[:space:]]*\\>",
"\\<[^[:space:]]+\\." + extentions + "+[^[:space:]]*\\>"];
// reset grep prefs
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
for (var j = 0; j < patterns.length; j++) {
// Set the pattern and search with GREP
app.findTextPreferences.findWhat = patterns[j];
// perform the search
var found = doc.findGrep();
// `found` is an array of text objects (if anything found)
for (var k = 0; k < found.length; k++) {
// I'm assuming that this function takes a text object as the 2nd parameter...
applyCharacterStyle(doc, found[k], charStyle);
}
}
If that doesn't help, please post a full (even if getting an error) script. It can be stripped down, but must be runable for us to test.
- Mark
Copy link to clipboard
Copied
Hello, Mark! Thank you for helping. Here is full code, unfortunately I could not run my with your changes, so here is the full unchanged version. It runs without errors, but only applyies the style to the last pattern.
Copy link to clipboard
Copied
Hello, Mark! Thank you for helping. Here is full code, unfortunately I could not run my with your changes, so here is the full unchanged version. It runs without errors, but only applyies the style to the last pattern.
Copy link to clipboard
Copied
Not "Text" researches but "Grep"! To be corrected everywhere.
(^/) The Jedi
Copy link to clipboard
Copied
I mean:
"app.findTextPreferences" ==> "app.findGrepPreferences"
"app.changeTextPreferences" ==> "app.changeGrepPreferences"
[I've not checked your patterns!]
(^/)
Copy link to clipboard
Copied
Oh God, that was so dumb mistake... Thank you very much for helping!
Copy link to clipboard
Copied
Haha, yeah I didn't spot that either! Doh!