Created
August 10, 2014 20:23
-
-
Save getflourish/f5798c511c2fbdf61e22 to your computer and use it in GitHub Desktop.
This file contains 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
// Selects all text layers that have the same text style as the reference text layer (command control t) | |
// init | |
var layerCount = 0; | |
var pageCount = 0; | |
var lastFoundOnPage = -1; | |
var selectedLayers = []; | |
var i = 0; | |
// We can only search for similar text layers when a reference layer is selected | |
if (selection.count() == 1) { | |
[doc showMessage: "Looking for similar text layers…"] | |
// Remember the reference text style | |
var reference = selection[0].style().textStyle().attributes(); | |
// Loop through pages | |
var pages = doc.pages().objectEnumerator(); | |
while (page = pages.nextObject()) { | |
i++; | |
// Loop through all children of the page | |
var layers = page.children().objectEnumerator(); | |
while (layer = layers.nextObject()) { | |
// Check if the layer is a text layer | |
if ([layer isKindOfClass:MSTextLayer]) { | |
if(layer.style().textStyle().attributes() == reference) { | |
[layer select:true byExpandingSelection:true]; | |
layerCount++; | |
if (i != lastFoundOnPage) { | |
pageCount++; | |
lastFoundOnPage = i; | |
} | |
} | |
} | |
} | |
} | |
// Show how many layers have been selected | |
[doc showMessage: layerCount + " layers on " + pageCount + " pages selected."] | |
} else { | |
[doc showMessage: "Please select a single reference text layer."] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What I did:
layer.setIsSelected(true);
Only the last change is relevant, the other changes may be lint optimizations.
For me this changed script selects the layers as expected without crashes.