Skip to main content
Inspiring
August 24, 2015
Answered

How can I find the target/result of a photoshop event?

  • August 24, 2015
  • 3 replies
  • 984 views

Hi all,

Is there a method of retrieving information about the results of a Photoshop event? For example, after a Delete event ("Dlt ") can I get any information on what was deleted?

Specifically my current needs are to find what layer was deleted after a delete event.

The relevant js code in my project is:

function registerPSEvent( typeIDs, clear ){

  // unregisters an even before adding it - prevents double events

  var regUnreg = null;

  if( clear ){

  console.log( 'Unregistering ' + typeIDs );

  regUnreg = 'PhotoshopUnRegisterEvent';

  } else {

  console.log( 'Registering ' + typeIDs );

  regUnreg = 'PhotoshopRegisterEvent';

  }

  var e = new CSEvent(

  'com.adobe.' + regUnreg,

  'APPLICATION',

  csInterface.getApplicationID(),

  csInterface.getExtensionID()

  );

  e.data = typeIDs;

  csInterface.dispatchEvent(e);

}

// s2t is simply an abbreviation of stringIDToTypeID

function addPSEventListener( typeStrings, callback, target ) {

  csInterface.evalScript( "s2t('"+typeStrings+"')", function(r){

  registerPSEvent( r, true );

  registerPSEvent( r );

  csInterface.addEventListener( 'PhotoshopCallback', callback.bind(target) );

  } );

}

addPSEventListener( 'delete', delLayerEventHandler, this );

delLayerEventHandler = function(e) {

  console.log(e);

  // here i would like to be able to get what was deleted

}

Thanks,

Tom

This topic has been closed for replies.
Correct answer clunty

I've just discovered that when an event is received event.data holds 2 ints.

I thought these 2 numbers were due to me using stringIDToTypeID rather than charIDToTypeID. However the second number is a way to access any attributes of the event. So I'm now using the below function to get info on the event:

function get_event_descriptor( id ) {

  var desc = new ActionDescriptor();

    try{

        desc.fromID(id);

        var aref = desc.getReference(s2t('null'));      

        var aref_obj = {

            dclass : t2s( aref.getDesiredClass( s2t( 'null' ) ) ),

            name : aref.getName(),

            // id : aref.getContainer().getName()

        };    

        return JSON.stringify( aref_obj );

    } catch(e) {

        //return false;

        return JSON.stringify(e.message);

    }

}

id is the 2nd int returned in event.data.

currently I've only dug around enough to ensure that the event paramater class is returned correctly but this is enough for my current needs.

3 replies

cluntyAuthorCorrect answer
Inspiring
August 27, 2015

I've just discovered that when an event is received event.data holds 2 ints.

I thought these 2 numbers were due to me using stringIDToTypeID rather than charIDToTypeID. However the second number is a way to access any attributes of the event. So I'm now using the below function to get info on the event:

function get_event_descriptor( id ) {

  var desc = new ActionDescriptor();

    try{

        desc.fromID(id);

        var aref = desc.getReference(s2t('null'));      

        var aref_obj = {

            dclass : t2s( aref.getDesiredClass( s2t( 'null' ) ) ),

            name : aref.getName(),

            // id : aref.getContainer().getName()

        };    

        return JSON.stringify( aref_obj );

    } catch(e) {

        //return false;

        return JSON.stringify(e.message);

    }

}

id is the 2nd int returned in event.data.

currently I've only dug around enough to ensure that the event paramater class is returned correctly but this is enough for my current needs.

Kukurykus
Legend
April 10, 2021

Is it possible to use .fromID() method without CEP? If so, could you post appropriate .jsx?

cluntyAuthor
Inspiring
August 24, 2015

I have found this post which seems to be able to achieve this by using app.notifier:

Re: How to get event target?

Ideally I would like to achieve this by using CSEvents

Kukurykus
Legend
April 10, 2021