Testing JavaScript on MAC OS
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
"it works flawlessly on Windows OS"
I don't see how it can since the function is not a trusted function. You have two methods that require a privileged context:
1) Setting the field fileSelect flag
2) doc.importTextData when the cPath is specified.
Copy link to clipboard
Copied
I have thought about that but it works when you check the Enable menu items JavaScript execution privileges in the Preferences.
When you check that, it does not require Privileged context. I have tried it on multiple machines.
Also, the console would mentiontion this:
I will post a new reply at the top. I have some more information from that person.
Copy link to clipboard
Copied
Oh, that's what that's for. ☺
Copy link to clipboard
Copied
UPDATE from the person:
They tried it both with an open document and without.
On a question “if they are using Acrobat Reader or not” they did not respond. I guess they are using Acrobat Pro, they are using it professionaly and work in printing.
Copy link to clipboard
Copied
What is the error with an open document?
Copy link to clipboard
Copied
The same. I will as them again about the Acrobat Reader.
It seems to be it.
Copy link to clipboard
Copied
Don't assume anything. We've seen it happen many times in the past that people were certain they were using Acrobat, but when we asked for full-window screenshots we saw it was actually Reader, or something else entirely...
Copy link to clipboard
Copied
True, I will ask them again.
Copy link to clipboard
Copied
OK, it was indeed Acrobat Reader.
Thanks everyone for your valuable time and a lot of useful insights into JavaScript.
Copy link to clipboard
Copied
For the future, I recommend getting them to send you a screenshot of the top left corner as the first step when something like this happens. I have encountered them same thing myself. Some people have Acrobat as well as Reader but don't set Acrobat as the default PDF viewer.
Copy link to clipboard
Copied
I will keep that in mind.
Thanks again for your time.
PS: Are you still working on that article about pre-filling the Save as dialog? It would help me tremendously on my next project.
Copy link to clipboard
Copied
Yes.
Copy link to clipboard
Copied
Excellent news. Could you PM me when it's ready?
Copy link to clipboard
Copied


-
- 1
- 2