Skip to content

Instantly share code, notes, and snippets.

@fwextensions
Created May 24, 2012 18:10
Show Gist options
  • Save fwextensions/2783196 to your computer and use it in GitHub Desktop.
Save fwextensions/2783196 to your computer and use it in GitHub Desktop.
Example of writing JSON-style info to a file
// ===========================================================================
try { (function() {
if (!fw.selection || !fw.selection.length) {
return;
}
var element = fw.selection[0],
info = {
name: element.name,
x: element.left,
y: element.top,
w: element.width,
h: element.height
},
filePath = fw.browseForFileURL("save"),
file;
if (!filePath) {
return;
}
Files.deleteFileIfExisting(filePath);
Files.createFile(filePath, "TEXT", "????");
file = Files.open(filePath, true);
file.write(info.toSource());
file.close();
})(); } catch (exception) {
if (exception.lineNumber) {
alert([exception, exception.lineNumber, exception.fileName].join("\n"));
} else {
throw exception;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment