Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created May 25, 2012 02:34
Show Gist options
  • Save davidortinau/2785434 to your computer and use it in GitHub Desktop.
Save davidortinau/2785434 to your computer and use it in GitHub Desktop.
Writing JSON-style info to a file
try { (function() {
if (!fw.selection || !fw.selection.length) {
return;
}
var json, filePath, file;
json = '{"sprites":[';
for(i=0;i < fw.selection.length;i++){
var element = fw.selection[i];
json += '{"key":"' + element.baseName + '","bounds":{"x":' + element.left + ',"y":' + element.top + ',"width":' + element.width + ',"height":' + element.height + '}},';
};
json = json.slice(0, json.length-1);
json += ']}';
filePath = fw.browseForFileURL("save");
if (!filePath) {
return;
}
Files.deleteFileIfExisting(filePath);
Files.createFile(filePath, "TEXT", "????");
file = Files.open(filePath, true);
file.write(json);
file.close();
})(); } catch (exception) {
if (exception.lineNumber) {
alert([exception, exception.lineNumber, exception.fileName].join("\n"));
} else {
throw exception;
}
}
@davidortinau
Copy link
Author

fixed name by changing it to baseName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment