Skip to main content
stuomas
New Participant
June 30, 2021
Question

CEP registering event handlers

  • June 30, 2021
  • 1 reply
  • 479 views

Hi,

I'm trying to register an event handler for `selectionsChanged` event.

main.js has

csInterface.evalScript('init()');

index.jsx has

function handleSelection(event) {
    if((event.type == 'selectionsChanged') && (event.object instanceof Thumbnail)) {
        alert("selections changed!");
        return {handled:false};
    }
}

function init() {
  app.eventHandlers.push( {handler: handleSelection} );
}

but the handler is never run. Why does this not work with CEP extension?

 

Thanks!

This topic has been closed for replies.

1 reply

Brainiac
July 1, 2021

if(event.object instanceof Document && event.type == 'selectionsChanged')

stuomas
stuomasAuthor
New Participant
July 1, 2021

Thanks for answer. You are right, it should be Document, but even if I remove the whole if-clause, it is never run. It seems to work only in start-up scripts but not CEP extensions? How to do it in extensions? Do I have to make a start-up script AND extension?

stuomas
stuomasAuthor
New Participant
July 2, 2021

I wish I had the answer, but I'm still learning CEP extensions.

 

The answer might be found in this Custom Metadata Panel which displays metadata when thumbnail selections are changed.

custom-metadata

 

You can get the source code at 

com.adobe.custom-metadata-cep.1.3.0.zxp

 

Or, install the extension and view the files in \CEP\extensions\com.adobe.custom-metadata-cep\

 

See selectEvent in this file: host\startupSelection.jsx

See SelectEventPlugin (as well as several other Events) in this file: \index.js

 


Thanks alot, that is actually very useful resource to look at for my project!!

 

It seems they also use a separate startup-script to catch the native event and forward it to the extension. I don't like this approach but since that is made by Adobe (?) it must be the right way. As a newbie I would just like to know why it is like that, and what is the right way to distribute such thing...