Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CEP registering event handlers

Community Beginner ,
Jun 30, 2021 Jun 30, 2021

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!

TOPICS
Scripting
457
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 01, 2021 Jul 01, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2021 Jul 01, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 01, 2021 Jul 01, 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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2021 Jul 01, 2021
LATEST

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines