<

How to Execute Code in the Acrobat JavaScript Console on a MacBook

Published on
19,943 Points
10,243 Views
2 Endorsements
Last Modified:
Awarded
Acrobat’s JavaScript is a great tool to extend the application, or to automate recurring tasks. There are several ways a JavaScript can be added to the application or a document (e.g. folder level scripts, validation scripts, event handling scripts, …), but regardless of how a script is written, chances are that the developer wants to test parts of the script in Acrobat’s Javascript console. This console window can be shown by either using the “Advanced>Document Processing>JavaScript Debugger…” menu item or Ctrl-J on Windows or Cmd-J on a Mac:
BlogPicsJS-Menu.png
After the console or debugger window comes up, the user can then enter Javascript and execute it…
BlogPicsJS-Debugger.png
… that is, as long as a full keyboard with a numeric keypad is used. In Adobe’s documentation, we find the following instructions to execute Javascript typed into the console window:

The JavaScript console allows you to evaluate single or multiple lines of code. There are three ways to evaluate JavaScript code while using the interactive console:

To evaluate a portion of a line of code, highlight the portion and press either the Enter key on the numeric keypad or press Ctrl + Enter.
To evaluate a single line of code, make sure the cursor is positioned on that line and press either the Enter key on the numeric keypad or press Ctrl + Enter.
To evaluate multiple lines of code, highlight those lines and press either the Enter key on the numeric keypad or press Ctrl + Enter.
That works fine as long as you have access to the numeric keypad, but on a MacBook or a MacBook Pro without that keypad. No key combination involving fn, ctrl, cmd or option with the Return or Enter key will result in the Javascript getting executed.

The virtual keyboard to the rescue: Mac OS comes with a handy keyboard viewer that allows us to send the correct key code to the application. To bring up the keyboard viewer, bring up the Mac OS System Preferences first and select the “Keyboard” category:
BlogPicsKeyboardViewer-1.png
Make sure that the option “Show Keyboard & Character Viewer in menu bar” is selected. Once this is done, you can access the keyboard viewer from the menu bar:
BlogPicsKeyboardViewer-2.png
Now comes the tricky part: Write some Javascript in the console window and place the cursor on the line you want to execute or select the snippet of the Javascript that should be executed. In the following example I’m using code from Adobe’s Javascript API documentation:
var menuItems = app.listMenuItems()
  for( var i in menuItems)
    console.println(menuItems[i] + "\n")

Open in new window

With the console prepped, bring up the keyboard viewer and start pushing keys – real keys that is: Hold down the “fn” and the “control” key, then move the mouse pointer to the “Enter” key on the keyboard viewer and click it…
BlogPicsJS-Debugger-6.png
… and voila!, the script gets executed:
BlogPicsJS-Debugger-7.png

This is not the most straight forward method, but at least it’s possible to use the Javascript console to execute code when using a MacBook.

This article was originally posted on my blog: http://khkonsulting.com/2010/03/javascript-console/
2
Comment
1 Comment
LVL 44

Author Comment

by:Karl Heinz Kremer
Here is a quick update: This is no longer necessary with Acrobat XI - Adobe finally added support for MacBook keyboards in the JavaScript console and script debugger.

The key combination Fn-Ctrl-Return will execute JavaScript in Acrobat XI.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Join & Write a Comment

Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month