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
//create panel for user to select file | |
var open = NSOpenPanel.openPanel(); | |
var fileTypes = [NSArray arrayWithObjects:@"json",nil]; | |
open.setAllowedFileTypes(fileTypes); | |
open.setCanChooseDirectories(true); | |
open.setCanChooseFiles(true); | |
open.setCanCreateDirectories(true); | |
open.setTitle("Import a Color Palette"); | |
open.setPrompt("Import Palette"); |
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 rgbToHex(r, g, b) { | |
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); | |
} | |
function colorFromString(value) { | |
var immutable = MSImmutableColor.colorWithSVGString_(value); | |
return MSColor.alloc().initWithImmutableObject_(immutable); | |
} | |
function alert(title, message){ |
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
@import 'common.js' | |
var onRun = function(context) { | |
var doc = context.document; | |
var selection = context.selection; | |
//make sure something is selected | |
if(selection.count() == 0){ | |
doc.showMessage("Please select a layer."); | |
}else{ |
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 exportJSON(layer, file_path){ | |
//initialize the layer array | |
var layerArray = []; | |
//create the variables | |
var layerName = String(layer.name()); | |
var layerFrame = layer.absoluteRect(); | |
var layerXpos = String(layerFrame.x()); | |
var layerYpos = String(layerFrame.y()); |
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
@import 'common.js' | |
var onRun = function(context) { | |
var doc = context.document; | |
var selection = context.selection; | |
//make sure something is selected | |
if(selection.count() == 0){ | |
doc.showMessage("Please select a layer."); | |
}else{ |
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 exportXML(layer, file_path){ | |
//initialize the root xml element | |
var root = [NSXMLElement elementWithName:@"document"]; | |
//initialize the xml object with the root element | |
var xmlObj = [[NSXMLDocument document] initWithRootElement:root]; | |
//create the variables | |
var layerName = layer.name(); | |
var layerFrame = layer.absoluteRect(); |
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
//create the xml file | |
var xmlData = [xmlObj XMLDataWithOptions:NSXMLNodePrettyPrint]; | |
//name the xml file the name of the layer and save it to the folder | |
[xmlData writeToFile:file_path+layerName+".xml"]; | |
var alertMessage = layerName+".xml saved to: " + file_path; | |
alert("Layer XML Exported!", alertMessage); |
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
//create the first child element and add it to the root | |
var layerElement = [NSXMLElement elementWithName:@"layer"]; | |
[root addChild:layerElement]; | |
//add elements based on variables to the first child | |
var layerNameElement = [NSXMLElement elementWithName:@"name" stringValue:layerName]; | |
[layerElement addChild:layerNameElement]; | |
var layerXPosElement = [NSXMLElement elementWithName:@"xPos" stringValue:layerXpos]; | |
[layerElement addChild:layerXPosElement]; |