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

AID: 3373
  • Status: Published

7040 points

  • By
  • TypeTips/Tricks
  • Posted on2010-07-06 at 13:51:05
Awards
  • Community Pick
  • Experts Exchange Approved
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
  • 90 KB
  • Screenshot of Acrobat's JavaScript menu
Screenshot of Acrobat's JavaScript menu

After the console or debugger window comes up, the user can then enter Javascript and execute it…
BlogPicsJS-Debugger.png
  • 21 KB
  • JavaScript Debugger
JavaScript Debugger

… 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
  • 46 KB
  • Keyboard Preferences
Keyboard Preferences

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
  • 15 KB
  • Keyboard Viewer Menu Item
Keyboard Viewer Menu Item

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

                                    
1:
2:
3:

Select allOpen 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
  • 133 KB
  • Keyboard Viewer Screenshot
Keyboard Viewer Screenshot

… and voila!, the script gets executed:
BlogPicsJS-Debugger-7.png
  • 358 KB
  • JavaScript Debugger Screenshot
JavaScript Debugger Screenshot


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://www.khk.net/wordpress/2010/03/23/javascript-console/
    Asked On
    2010-07-06 at 13:51:05ID3373
    Tags

    Adobe Acrobat

    ,

    PDF

    ,

    MacBook

    ,

    JavaScript

    ,

    Acrobat JavaScript

    ,

    debugging

    ,

    JavaScript Console

    ,

    execute JavaScript

    Topic

    Adobe Acrobat

    Views
    1867

    Comments

    Add your Comment

    Please Sign up or Log in to comment on this article.

    Join Experts Exchange Today

    Gain Access to all our Tech Resources

    Get personalized answers

    Ask unlimited questions

    Access Proven Solutions

    Search 3.2 million solutions

    Read In-Depth How-To Guides

    1000+ articles, demos, & tips

    Watch Step by Step Tutorials

    Learn direct from top tech pros

    And Much More!

    Your complete tech resource

    See Plans and Pricing

    30-day free trial. Register in 60 seconds.

    Loading Advertisement...

    Top Adobe Acrobat Experts

    1. khkremer

      62,970

      Master

      10 points yesterday

      Profile
      Rank: Genius
    2. captainreiss

      23,100

      0 points yesterday

      Profile
      Rank: Genius
    3. dlmille

      14,450

      0 points yesterday

      Profile
      Rank: Genius
    4. puppydogbuddy

      13,300

      0 points yesterday

      Profile
      Rank: Genius
    5. Nrisimha

      12,800

      0 points yesterday

      Profile
      Rank: Guru
    6. joewinograd

      8,640

      0 points yesterday

      Profile
      Rank: Wizard
    7. thinkpads_user

      8,472

      0 points yesterday

      Profile
      Rank: Genius
    8. jcimarron

      6,600

      0 points yesterday

      Profile
      Rank: Genius
    9. cs97jjm3

      6,600

      0 points yesterday

      Profile
      Rank: Genius
    10. flubbster

      6,000

      0 points yesterday

      Profile
      Rank: Genius
    11. Carlisle_Agent

      6,000

      0 points yesterday

      Profile
    12. EddieShipman

      5,768

      0 points yesterday

      Profile
      Rank: Genius
    13. DaveBaldwin

      5,500

      0 points yesterday

      Profile
      Rank: Genius
    14. mplungjan

      4,964

      0 points yesterday

      Profile
      Rank: Savant
    15. wobbled

      4,800

      0 points yesterday

      Profile
      Rank: Sage
    16. leakim971

      4,800

      0 points yesterday

      Profile
      Rank: Genius
    17. travisfox

      4,664

      0 points yesterday

      Profile
    18. JillofallTradesMistressofNone

      4,500

      0 points yesterday

      Profile
    19. Run5k

      4,000

      0 points yesterday

      Profile
      Rank: Genius
    20. NKOWA

      4,000

      0 points yesterday

      Profile
      Rank: Master
    21. nap0leon

      4,000

      0 points yesterday

      Profile
      Rank: Sage
    22. medvedd

      4,000

      0 points yesterday

      Profile
      Rank: Sage
    23. IT_Crowd

      4,000

      0 points yesterday

      Profile
      Rank: Guru
    24. sravi2208

      4,000

      0 points yesterday

      Profile
    25. PRRcomputers

      4,000

      0 points yesterday

      Profile

    Hall Of Fame