I'm extracting some data from an InDesign INDD file using a script. I'd like to save my data in a txt or json file, but my file is not saving successfully.
var data = 'string of data';
var filename = 'CS111.json';
var file = new File(filename);
var path = file.saveDlg(); //returns a valid path, but with spaces as '%20'
var write = file.write(data); //returns false
I find that the write step will sometimes fail if I don't set the encoding.
//Define path and file name var path = '~/Documents/'; var filename = 'filename.txt'; //Create File object var file = new File(path + filename); file.encoding = 'UTF-8'; file.open('w'); file.write('data here'); file.close();