Click to See Complete Forum and Search --> : JavaScript: Add new menuitem in Acrobat 5.0 [Resolved]
RobDog888
Sep 19th, 2003, 04:49 PM
I am having trouble getting this script to run. I have it entered at
the Document level and I need to know where its going wrong.
function APD_Menu(){
app.addMenuItem({cName: "Save to Working dir...", cParent: "File", cExec: "app.alert("Save to Working directory!");",cEnable: "event.rc = (event.target != null);",nPos: 0});
}
When I try to call my function it gives the error - "SyntaxError: syntax error undefined"
Any ideas or suggestions?
Thanks in advance for any help on this.
RobDog888
Sep 19th, 2003, 06:23 PM
This is working so far.
function APD_Menu(){
app.addMenuItem({ cName: "Save to Working Dir...", cParent: "File", cExec: "app.alert(this.path)", cEnable: "event.rc = event.target != null",nPos: 7});
}
CornedBee
Sep 23rd, 2003, 02:00 AM
"app.alert("Save to Working directory!");",
Try masking the inner quotes:
"app.alert(\"Save to Working directory!\");",
RobDog888
Sep 25th, 2003, 01:42 PM
I finally got it to add the menu item and execute some code.
Now I just need to see if I can get it to prompt for verification
before the saveas and handel the response.
Global.WorkingDir is a global static variable that I setup in
another script to contain the absolute path.
var sPos = "5";
app.addMenuItem({cName: "Save to Working Dir...", cParent: "File", cExec: "var aDocs = app.activeDocs; var myForm = aDocs [0]; myForm.saveAs(global.WorkingDir + 'Test.pdf');" , nPos: sPos});How do I get a function to return a value so I can embed the
function call into the addMenuItem call?
I can use that to determine if the file is to be saved or not.
CornedBee
Sep 25th, 2003, 03:04 PM
Just add a return statement? Or is there any specific reason why this wouldn't work?
RobDog888
Sep 25th, 2003, 04:20 PM
Here is the update that is working.
var sPos = "5";
app.addMenuItem({cName: "Save to Working Dir...", cParent: "File", cExec: "event.rc = SaveWorking() != 2", cEnable: "event.rc = TypeOfDocSave() != 0", nPos: sPos});
function TypeOfDocSave() {
var d = this.info;
var sTitle = d.Title
var sGood = sTitle.indexOf("APD");
if (event.target == null) {
return 0;
}
if (sGood == "0") {
return 1;
}
else {
return 0;
}
}
function SaveWorking() {
var cResp = app.alert('Save to - ' + global.WorkingDir + 'Test.pdf',2,1);
if (cResp == 1) {
app.alert('Saving to - ' + global.WorkingDir + 'Test.pdf',3,0);
this.saveAs(global.WorkingDir + 'Test.pdf')
return 1;
}
if (cResp == 2) {
app.alert('Canceled',1,0);
return 2;
}
}
This will only be enabled and execute if the document has "APD" in the title.
If there are other documents opened, when switched to them the menu item is disabled!
I still need filename generation code for this part of my prject to be complete.
Review my other thread for the details, please.
Any ideas?
Thanks for the assistance.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.