Last active
October 2, 2016 22:08
-
-
Save marianomike/4e1f4c606cc13ff927dd6817371a5f82 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
//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