Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Testing JavaScript on MAC OS

Explorer ,
Feb 20, 2025 Feb 20, 2025

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

TOPICS
JavaScript , PDF forms
843
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2025 Feb 20, 2025

"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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2025 Feb 20, 2025

I have thought about that but it works when you check the Enable menu items JavaScript execution privileges in the Preferences. 

DavidSmerda_1-1740069942524.pngexpand image

 

When you check that, it does not require Privileged context. I have tried it on multiple machines. 

Also, the console would mentiontion this: 

DavidSmerda_0-1740069865564.pngexpand image

I will post a new reply at the top. I have some more information from that person. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2025 Feb 20, 2025

Oh, that's what that's for. ☺

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2025 Feb 20, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2025 Feb 20, 2025

What is the error with an open document?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2025 Feb 20, 2025

The same. I will as them again about the Acrobat Reader.

It seems to be it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2025 Feb 20, 2025

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2025 Feb 20, 2025

True, I will ask them again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2025 Feb 21, 2025

OK, it was indeed Acrobat Reader. 

Thanks everyone for your valuable time and a lot of useful insights into JavaScript.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2025 Feb 21, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2025 Feb 21, 2025

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2025 Feb 21, 2025

Yes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2025 Feb 21, 2025

Excellent news. Could you PM me when it's ready?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2025 Feb 25, 2025
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines