Last active
February 1, 2019 07:12
-
-
Save sonburn/f7b8388817894a4787dd248a26bf91b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findStringInTextLayers(textToFind,exactMatch,currentPage) { | |
| var predicate = NSPredicate.predicateWithFormat("className == %@","MSTextLayer"), | |
| textLayers = NSMutableArray.array(); | |
| if (currentPage == 1) { | |
| var page = context.document.currentPage(); | |
| textLayers.addObjectsFromArray(page.children().filteredArrayUsingPredicate(predicate)); | |
| } else { | |
| var pages = context.document.pages(), | |
| pageLoop = pages.objectEnumerator(), | |
| page; | |
| while (page = pageLoop.nextObject()) { | |
| textLayers.addObjectsFromArray(page.children().filteredArrayUsingPredicate(predicate)); | |
| } | |
| } | |
| var textLayerLoop = textLayers.objectEnumerator(), | |
| textLayer, | |
| foundMatch = 0; | |
| while (textLayer = textLayerLoop.nextObject()) { | |
| if (exactMatch == 1 && textLayer.stringValue() == textToFind || exactMatch == 0 && textLayer.stringValue().indexOf(textToFind) != -1) { | |
| log(textLayer.objectID()); | |
| log(textLayer.stringValue()); | |
| log("..."); | |
| foundMatch++; | |
| } | |
| }; | |
| log("Found " + foundMatch + " matches for \"" + textToFind + "\""); | |
| } | |
| // text to find, exact match (1) or fuzzy match (0), current page (1) or all pages (0) | |
| findStringInTextLayers("9.",0,0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment