Testing JavaScript on MAC OS
Hello,
I have been editing a script originally made by Karl Heinz (link to the original script) and it works flawlessly on Windows OS. But after sharing this script with another pearson on MAC OS, they can't make it work.
I have made sure that the obtained file path would be compatible with both Windows and MAC OS via the replace() method.
I can't check it personally (I do not own/have access to MAC) and further investigation is quite delayed due to a different time-zone.
Could anyone check the script and tell me what's going on?
app.addMenuItem ({cName: "DataMerge", cParent: "Edit", cExec: "DataMergeFx()"});
function DataMergeFx() {
var sFilePath = this.path;
var sMetadata = this.metadata;
var newDoc = this.extractPages(0);
newDoc.metadata = sMetadata;
var tmpField = newDoc.addField("Directory", "text", 0, [0,0,100,100]);
tmpField.hidden = true;
tmpField.fileSelect = true;
tmpField.browseForFileToSubmit();
var txtValue = tmpField.valueAsString;
var txtPath = "/" + txtValue.replace(/:\\/g,"/").replace(/\\/g,"/").replace(/:/g,"/");
var err = 0;
var idx = 0;
while (err == 0) {
err = this.importTextData(txtPath, idx);
newDoc.flattenPages();
if (err == -1)
app.alert("Error: Cannot Open File");
else if (err == -2)
app.alert("Error: Cannot Load Data");
//else if (err == -3) {}
else if (err == 1)
app.alert("Warning: User Cancelled File Select");
else if (err == 2)
app.alert("Warning: User Cancelled Row Select");
else if (err == 3)
app.alert("Warning: Missing Data");
else if (err == 0) {
newDoc.insertPages({cPath: sFilePath});
idx++;
}
}
newDoc.deletePages(0);
var nPages = newDoc.numPages;
for(i = nPages - 1; i>0; i--) {
newDoc.movePage(0, i);
}
this.resetForm();
this.dirty = false;
}The person has enabled menu items JavaScript execution privileges and in the last conversation, they mentioned that the console error message looks like this:
TypeError: this.extractPages() is not a function
5:Folder-Level:App:DataMerge.js...which does not make sense to me. Nithing like this appears on Windows and the extractPages() method is well defined.
Everything (the script file and a testing file with random namelist) can be accessed via this link.
Thanks a lot,
David
