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

Explorer ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

420

Likes

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

correct answers 1 Correct Answer

Explorer , Aug 27, 2015 Aug 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 = {     
...

Likes

Translate

Translate
Explorer ,
Aug 24, 2015 Aug 24, 2015

Copy link to clipboard

Copied

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

Likes

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
Adobe Community Professional ,
Apr 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

Likes

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
Enthusiast ,
Aug 26, 2015 Aug 26, 2015

Copy link to clipboard

Copied

Using javascript on CC2014

//  to catch each one event (notifiers) properties, use this:

for (var a=0; a<app.notifiers.length; a++) {

    var event_ = app.notifiers.event;

    $.writeln(event_);

    var eventFile_ = app.notifiers.eventFile;

    $.writeln(eventFile_);

    var eventClass_ = app.notifiers.eventClass;

    $.writeln(eventClass_);

    // if you want to delete a specific one, reading 1,2 or 3 inner properties, use this:

    // if ([condition]) app.notifiers.remove();

}

//~ // but you can remove all notifiers (events) at the same time like this

//~ app.notifiers.removeAll();

Likes

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
Explorer ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

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.

Likes

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
Adobe Community Professional ,
Apr 10, 2021 Apr 10, 2021

Copy link to clipboard

Copied

LATEST

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

Likes

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