Created
July 14, 2015 11:21
-
-
Save abynim/49e82833edde186e0b4a 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
// Hex to Color - helper function | |
var hexToColor = function(hex, alpha) { | |
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex), | |
red = parseInt(result[1], 16) / 255, | |
green = parseInt(result[2], 16) / 255, | |
blue = parseInt(result[3], 16) / 255, | |
alpha = (typeof alpha !== 'undefined') ? alpha : 1; | |
return NSColor.colorWithCalibratedRed_green_blue_alpha(red, green, blue, alpha) | |
} | |
// Select a Text Layer with at least 4 characters | |
var selection = context.selection, | |
textLayer = selection.firstObject(); | |
var range = NSMakeRange(1,3) | |
var color = hexToColor('4A90E2') | |
textLayer.setIsEditingText(true) | |
textLayer.addAttribute_value_forRange(NSForegroundColorAttributeName, color, range) | |
textLayer.setIsEditingText(false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment