Copy link to clipboard
Copied
I'm making a color wheel panel and it's almost done. What I still need is to create an eventlistener for when foreground or background color is changed.
I know that I can get the foreground color with:
_Adobe.JSXInterface.app.foregroundColor.rgb
BUT does anybody know how to create an eventlistener that tells me when it's changed?
Copy link to clipboard
Copied
try {
if (arguments.length >= 2) {
var desc = arguments[0];
var event = arguments[1];
if (event == charIDToTypeID('setd')) {
var ref = desc.getReference(charIDToTypeID('null'));
var cls = ref.getDesiredClass();
if (cls == charIDToTypeID('Clr ')) {
var property = ref.getProperty();
if(property == charIDToTypeID('FrgC') ){
alert('foreground color changed');
}
}
}
}
} catch (e) {}
Copy link to clipboard
Copied
Michael L Hale wrote:
try { if (arguments.length >= 2) { var desc = arguments[0]; var event = arguments[1]; if (event == charIDToTypeID('setd')) { var ref = desc.getReference(charIDToTypeID('null')); var cls = ref.getDesiredClass(); if (cls == charIDToTypeID('Clr ')) { var property = ref.getProperty(); if(property == charIDToTypeID('FrgC') ){ alert('foreground color changed'); } } } } } catch (e) {}
Thank you for reply!
As I understand it, that's the check I have to do when the event is triggered. But what I was looking for here is the event code that triggers your example code.
For example..
The example code could be in a function like this.
function onPSForegroundColorChanged() { try { if (arguments.length...... } catch(e) }
Then I would have to add an event listener somewhere that would trigger this function when foreground color is being changed?
or did I miss something?
Copy link to clipboard
Copied
The code I posted is an example of an event script that tests for foregroundColor change. When installed as a notifier it will run when the user changes the foregroundColor using the colorPicker or eyedropper. There may be other ways to change the color you will need to account for. You should of course replace the alert with more useful code.
One way to install the event handler would be:
if(!app.notifiersEnabled) app.notifiersEnabled = true;// make sure notifier are enabled
var hasEvent = false;// flag for event test
for(var e = 0;e<app.notifiers.length;e++){// search the notifier for the event
if(app.notifiers
.event == 'setd') hasEvent = true;// if found set flag }
if(!hasEvent) {// if event not found, install
var eventFile = new File("~/desktop/setd listener.jsx");// replace with path to where you saved the event handler posted above
app.notifiers.add( "setd", eventFile, charIDToTypeID('Clr '));// event, jsxFile, psClass. Adding the class argument will limit when PS fires the event
// by including the class argument PS will only fire the event script if the event uses the color class. That should improve performance by not running the
// the event script everytime a 'setd' event happens
}
Copy link to clipboard
Copied
Thank you, that was exactly what I was looking for.
Wierd though that for some reason I can not use that File()
var eventFile = new File("test.jsx");
It just keeps giving me TypeError: Result of expression 'File'[[object FileConstructor]] is not a constructor.
Maybe I'm missing some import file or something..
Copy link to clipboard
Copied
From the code in your original post it looks like you are using the CS-SDK( or Panel SDK ). I don't know how to create a file object with ActionScript. You may want to ask in the CS-SDK user forum.
Copy link to clipboard
Copied
Can you please tell me where to put these codes?