如何使用 InDesign 脚本保存文本文件?
How do I save a text file using an InDesign script?
我正在使用脚本从 InDesign INDD 文件中提取一些数据。我想将我的数据保存在 txt 或 json 文件中,但我的文件没有保存成功。
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'
file.changePath(path);
var write = file.write(data); //returns false
file.close();
我在这里错过了什么?该文件未显示在所选文件夹中。
使用 InDesign 保存文件至少有四个步骤 Javascript:获取路径和文件名、创建文件对象、打开文件、写入文件和关闭文件。
我发现如果不设置编码,写入步骤有时会失败。
//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();
文档:File
class, .open()
, .write()
我正在使用脚本从 InDesign INDD 文件中提取一些数据。我想将我的数据保存在 txt 或 json 文件中,但我的文件没有保存成功。
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'
file.changePath(path);
var write = file.write(data); //returns false
file.close();
我在这里错过了什么?该文件未显示在所选文件夹中。
使用 InDesign 保存文件至少有四个步骤 Javascript:获取路径和文件名、创建文件对象、打开文件、写入文件和关闭文件。
我发现如果不设置编码,写入步骤有时会失败。
//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();
文档:File
class, .open()
, .write()