Copy link to clipboard
Copied
Hello all,
It seems actions performed by scripts do not trigger events.
By events I mean those you can listen to by registering a notifier :
app.notifiers.add( "setd", new File("my_color_change_listener.jsx"), "Clr ");
The line above will make the specified script be notified when foreground (or background) color is modified.
But if I change foreground color using a script, for example :
app.foregroundColor = myColor;
Then no event will be sent. It is I believe the same with all events (changing layer, opening a document...)
So how can I send a event using a script ?
Thanks in advance,
Yannick
Copy link to clipboard
Copied
I do not think its possible events are only triggered from top level user action not from an action, script or plug-in. Most likely to prevent endless recursion, If you want to trigger something why not simply do the something the action or script.
Copy link to clipboard
Copied
Well to disable them by default is one thing, but you should be able to send events if you want to. Endless recursion happens only if you change color in a script that listens to color changes, which you'll admit is pretty silly
I see at least two reasons for using events instead of calling the action directly :
1. The most important, it allows for communicating between plugins
2. reacting to an event can make your code a lot cleaner. If I want to do something when color is changed, I do not want to think about it each time I change color in a script.
Copy link to clipboard
Copied
All I can write is what I see in Adobe scripting guide. Have no idea of what Adobe is trying to convay other then scripts code does not generate notifications. Written in an Adobe way to confuse their users. For the way its written seems to leave the door open exceptions.
Photoshop Scripting guide page 49
"NOTE: Notification generally does not take effect on events that occur inside of a script, because these events are embedded with in an "AdobeScriptAutomation Scripts" event"
Then in Photoshop JavaScript Reference page 136
"Note: Events that occur within scripts do not generally trigger notifiers, because they occur inside a "play
script" event"
Copy link to clipboard
Copied
I think those parts of the guide are saying about the same thing, the frist just using the newer term for the play event.
A script doesn't really have events handlers, they have notifiers. That is say the script can get a notice that an event has occured. But the event has already been handeled by Photoshop. Even if a script triggered events, the event handler script would not be able to run while the main script is running. There doesn't seem to be a 'stack' for waiting script calls. If the call is block it's dropped.
I don't see how event handlers allow communication between plugins. Nor do I understand how it makes code cleaner.
Event handlers are about being able to respond to user's actions. You have control over what happens in your script. If you want to do something when your script does something then just add that part of the code to your script.
Copy link to clipboard
Copied
Well now I know you can't send events
I'll still explain why you should be able to.
I think events are used to keep in sync with photoshop's state. If you want to know when color changes, you want to know when it changes whether the user did it or a script did it.
I'm using a third party color picker plugin.
This plugin listens to color changes.
This means this plugin is not notified when I change color using a script, and I can't call it explicitly.
And even if I could (if it was a script of mine), I would have to add this explicit call wherever I change color, which is poor design (I can forget to call it somewhere... If I remove the plugin I have to remove all calls)