Copy link to clipboard
Copied
I'm developing an extension that creates a range of data as a javascript object. I'd like to allow the user to click a "save" button, navigate to a directory (optional), and save the json file created in the HTML session. I tried a download link (similar to what I'd do on a web page), but that doesn't save out the file. Is there an efficient way for a user to save out txt,json, or xml data from an HTML Panel?
Alright, I've got a working version using jsx:
function saveJSON(txt)
{
txt=JSON.stringify(txt)
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var Path = app.activeDocument.path;
var saveFile = File(Path + "/" + Name +".json");
if(saveFile.exists)
saveFile.remove();
saveFile.encoding = "UTF8";
saveFile.open("e", "TEXT", "????");
saveFile.writeln(txt);
saveFile.close();
}
Reference this post for getting JSON.stringify on the JSX side: HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.
...Copy link to clipboard
Copied
Maybe you can do it with just javascript, jquery, etc.
What I would do is create a hybrid plugin and pass whatever data you want from the extension back to the C++. There you can use the API to pop a Save as dialog.
Copy link to clipboard
Copied
btempleton1982 Thanks for the tip! Does anyone have a simpler solution that doesn't involve hybrid plugins?
Copy link to clipboard
Copied
Alright, I've got a working version using jsx:
function saveJSON(txt)
{
txt=JSON.stringify(txt)
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var Path = app.activeDocument.path;
var saveFile = File(Path + "/" + Name +".json");
if(saveFile.exists)
saveFile.remove();
saveFile.encoding = "UTF8";
saveFile.open("e", "TEXT", "????");
saveFile.writeln(txt);
saveFile.close();
}
Reference this post for getting JSON.stringify on the JSX side: HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more