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
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 = {
Copy link to clipboard
Copied
I have found this post which seems to be able to achieve this by using app.notifier:
Ideally I would like to achieve this by using CSEvents
Copy link to clipboard
Copied
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();
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.
Copy link to clipboard
Copied
Is it possible to use .fromID() method without CEP? If so, could you post appropriate .jsx?