These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need help creating a custom search menu command

mdailey77
Registered: Apr 8 2011
Posts: 4
Answered

I work for a scientific publisher and I'm trying to create a custom search menu command in Acrobat using Javascript. I want to be able to search for multiple terms (aux electronic suppl supporting online repository dynamic content appendix appendices) at once just by clicking on a menu command. I don't have any experience coding in Javascript, but I managed to cobble some code together.
 
Here is what I have so far:
 
function auxmatSearch(){
app.alert("Aux Mat Keyword Search:" + this.cQuery);
}
search.matchCase = false;
 
search.wordMatching = MatchAnyWord;
 
search.bookmarks = false;
 
search.query("aux electronic suppl supporting online repository dynamic content appendix appendices","ActiveDoc");
 
app.addMenuItem ({cName: "Aux Mat Search", cParent: "Tools", cExec: "auxmatSearch()"
});
  
I know some of the code is wrong since the command doesn't appear in Acrobat's menu, but I don't know what part is wrong or if I'm missing some code. I searched for similar examples of custom search scripts but couldn't find any. I'm stuck at the moment. Does anyone have any suggestions?

My Product Information:
Acrobat Pro Extended 9.4.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
First of all, your curly brackets are all wrong.
Secondly, all of your search commands should be inside the function.
Thirdly, you need to place MatchAnyWord inside double-quotes, since it's a string.
But the most important thing is that your alert will not show anything. The search object is used to launch the built-in search window of Acrobat. It doesn't return any values.

You can use something like this (in a folder-level script):

function auxmatSearch(){
search.matchCase = false;
search.wordMatching = "MatchAnyWord";
search.bookmarks = false;
search.query("aux electronic suppl supporting online repository dynamic content appendix appendices","ActiveDoc");
}

app.addMenuItem ({cName: "Aux Mat Search", cParent: "Tools", cExec: "auxmatSearch()"});

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mdailey77
Registered: Apr 8 2011
Posts: 4
Thank you for your answer. I figured there was something wrong with my code. I put your code in a plain text file, named it "auxmatsearch.js" and put the file in this folder: C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts but the command doesn't show up in the Tools menu. Do I have to activate it somehow? This is very new to me, so any suggestions would be great. Thanks again.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Make sure the file extension is really js and not txt, first of all.
Secondly, make sure the preferences in Acrobat allow JavaScript menu items privileges.
Also, tick the box to show the console on errors and warnings. Then restart Acrobat and see what happens.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mdailey77
Registered: Apr 8 2011
Posts: 4
I was able to add the menu item to the Tools menu after some trial and error, but when I select the custom menu command an error box pops up. The error box just has an X icon and the name of the function, auxmatSearch. I'm stuck again. The javascript console doesn't pop up with any errors when I first open Acrobat. Not sure why it doesn't perform the search.

Here is what I have for the code:

function auxmatSearch()
{
search.matchCase = false;
search.wordMatching = "MatchAnyWord";
search.bookmarks = false;
search.query("aux electronic suppl supporting online repository dynamic content appendix appendices", "ActiveDoc");
}
app.addMenuItem({cName:"Aux Mat Search", cParent: "Tools", cExec: "app.alert('auxmatSearch'); "});


I put the above code in a javascript editor and saved it as auxmatsearch.js and put it in C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts

I know I'm missing something, not sure what. If anyone has any suggestions, I would great appreciate it.

Thanks in advance,

Matt
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
You're not executing the function at all. You're just creating an alert with the text 'auxmatSearch' to appear...
To call the function change this:
cExec: "app.alert('auxmatSearch'); "
to this:
cExec: "auxmatSearch()"

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

mdailey77
Registered: Apr 8 2011
Posts: 4
Thank you so much try67 for your help. It works!