Forked from bomberstudios/Change Font.sketchplugin
Last active
August 29, 2015 14:19
-
-
Save annikaC/ae33aeeea2b3b175efbf 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
// Change font (ctrl a) | |
var font_name = [doc askForUserInput:"Font name:" initialValue:"Arial"]; | |
function check_layer(layer){ | |
log("Checking layer " + layer + " of klass: " + [layer class]) | |
switch ([layer class]) { | |
case MSTextLayer: | |
log("Found text layer!") | |
layer.setFontPostscriptName(font_name); | |
break; | |
case MSPage: | |
case MSLayerGroup: | |
case MSArtboardGroup: | |
var sublayers = [layer layers]; | |
log("This is a group/artboard/page with " + [sublayers count] + " sublayers") | |
for(var i=0; i < [sublayers count]; i++) { | |
var sublayer = sublayers[i]; | |
check_layer(sublayer); | |
} | |
break; | |
} | |
} | |
log("################################################################") | |
// Use selection, if any | |
if(selection && [selection count]){ | |
for (var i = 0; i < [selection count]; i++) { | |
check_layer(selection[i]); | |
} | |
} else { | |
// Otherwise, loop trough pages, artboards & layers | |
var pages = [doc pages]; | |
for (var i = 0; i < [pages count]; i++) { | |
var current_page = pages[i]; | |
if ([[current_page artboards] count]) { | |
log("Traversing artboards") | |
for (var i = 0; i < [[current_page artboards] count]; i++) { | |
var artboard = [current_page artboards][i] | |
check_layer(artboard) | |
} | |
} else { | |
log("Page has no artboards") | |
check_layer(current_page) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment