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

CEP registering event handlers

Community Beginner ,
Jun 30, 2021 Jun 30, 2021

Copy link to clipboard

Copied

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

Views

244

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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