Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abynim/49e82833edde186e0b4a to your computer and use it in GitHub Desktop.
Save abynim/49e82833edde186e0b4a to your computer and use it in GitHub Desktop.
// 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