Skip to content

Instantly share code, notes, and snippets.

@marianomike
Last active October 2, 2016 22:08
Show Gist options
  • Save marianomike/4e1f4c606cc13ff927dd6817371a5f82 to your computer and use it in GitHub Desktop.
Save marianomike/4e1f4c606cc13ff927dd6817371a5f82 to your computer and use it in GitHub Desktop.
//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");
open.runModal();
//import the selected file and parse to JSON object
var filePath = open.URLs().firstObject().path();
var fileContents = NSString.stringWithContentsOfFile(filePath);
var paletteContents = JSON.parse(fileContents);
//create array to hold JSON object for easy reference
var palette = [];
for(var x in paletteContents){
palette.push(paletteContents[x]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment