Skip to main content
JADarnell
Inspiring
February 18, 2014
Question

Making an event listener work (InDesign CC Windows 8).

  • February 18, 2014
  • 2 replies
  • 1253 views

Hello everyone.

I am tryingn to figure out how to make eventListeners work and something is just not clicking.

I wrote this very simple script that looks like this:

main();

function main()

{

    app.eventListeners.add("afterSelectionChanged", myEventHandler);

}

function myEventHandler(myEvent)

{

    alert("Something was selected", "Selection change");

}

When I run this script through ExtendScript and then go to the document and select a rectangle, I get the following error message twice:

"The requested action could not be completed because the object no longer exists."

I attempted to run it through the scripts panel to see if that made any difference, but when I attempted to save the file Windows told me that I need to contact the administrator to get permission to write in the Scripts Panel folder.  I'm working on that while I wait for any answer that might come forth.

This topic has been closed for replies.

2 replies

Participant
December 2, 2016

Maybe it's too late, but for the future. For me these two lines

#target "InDesign"

#targetengine "session"

solved the problem.

Marc Autret
Legend
February 19, 2014

Hi,

As you need a persistent function (myEventHandler), you also need to target a persistent engine:

#targetengine myEngine

(As for the file problem in Windows, I suggest you google your question. AFAIK this is a known (boring) issue related to writing permissions in the C: drive or something like that.)

@+

Marc

Participating Frequently
February 21, 2014

Thanks Mark.

   My apologies for a tiny bit of confusion.  I was not looking for an answer to my Windows predicament.  I was just whining.  And I figured it out after about an hour of pounding the keyboard.

   WRT the contribution to the main question I will give it a whirl soon and write back with my results. 

Participating Frequently
February 21, 2014

Adding the #targetengine myEngine directive did indeed fix the problem.  Thank you Mark.