Script bugs when launched by notifier

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Ray
Posts: 7
Joined: Tue Aug 09, 2016 9:27 am

Script bugs when launched by notifier

Post by Ray »

Hello,
I want to execute a script every time the selected color is changed.
I wrote this 2 files:

a notifier (colornotifier.jsx):

Code: Select all

app.notifiersEnabled = true;
var eventFile = new File(app.path + "/Presets/Scripts/color_script.jsx");
app.notifiers.add("setd", eventFile);
and the script (color_script.jsx):

Code: Select all


#target photoshop
alert("color changed");
The script works fine when i change the color from the Color Picker but, when a pick a color with the Eyedropper, ExtendScript Toolkit launches and stops the execution of the script.

Thanks
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Script bugs when launched by notifier

Post by Kukurykus »

To be honest I never knew how to use notifiers in Photoshop though I always wanted to learn it, and you gave me just an answer. It's good because I thougth even to combine my script with X-Mouse Button Control (in quite new Chording mode) http://highrez.co.uk, or some Auto Hot Key script https://autohotkey.com. Now it's not needed at least for me, as I tested it and it worked without launching ESTK after picking a colour.

What Windows and Photoshop do you use? Is that ESTK you have installed together with your Photoshop? For example if I had .jsx files set to open in ESTK 1.0 (if there wasn't #target photoshop) then scripts woldn't work in CS5.1 calling them from Photoshop. They would work if I reinstalled CS5.1. They'd become white-gray instead of old white-blue-red icons. I think there may be other reason though.

btw, where did you find name of eyedropper notifier ('setd' I guess)? Are there some other where you looked up?
Ray
Posts: 7
Joined: Tue Aug 09, 2016 9:27 am

Re: Script bugs when launched by notifier

Post by Ray »

I use photoshop CS3 and windows 7, ESTK was intalled with photoshop, in fact ESTK launches only when i use the color picker with alt shortcut.
To solve the problem I have temporary renamed ESTK executable so it cannot be found but my computer slows down (probably because he's searching for the executable). Do you know how to fix this problem ?

About the notifier i don't realy understand everything but i can show you my code, it's not very clean but it works:

colornotifier.jsx:

Code: Select all

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[e].event == 'setd')
hasEvent = true;// if found set flag
}

if(!hasEvent)
{
// if event not found, install
var eventFile = new File(app.path + "/Presets/Scripts/ConvertToSnesColors.jsx");// replace with path to where you saved the event handler posted above
app.notifiers.add( "setd", eventFile);// 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
}
color_script.jsx:

Code: Select all


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') || property == charIDToTypeID('BckC') )
{

var rgb8to5Nearest = [0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24, 24, 33, 33, 33, 33, 33, 33, 33, 33, 33, 41, 41, 41, 41, 41, 41, 41, 41, 49, 49, 49, 49, 49, 49, 49, 49, 57, 57, 57, 57, 57, 57, 57, 57, 66, 66, 66, 66, 66, 66, 66, 66, 66, 74, 74, 74, 74, 74, 74, 74, 74, 82, 82, 82, 82, 82, 82, 82, 82, 90, 90, 90, 90, 90, 90, 90, 90, 99, 99, 99, 99, 99, 99, 99, 99, 99, 107, 107, 107, 107, 107, 107, 107, 107, 115, 115, 115, 115, 115, 115, 115, 115, 123, 123, 123, 123, 123, 123, 123, 123, 132, 132, 132, 132, 132, 132, 132, 132, 132, 140, 140, 140, 140, 140, 140, 140, 140, 148, 148, 148, 148, 148, 148, 148, 148, 156, 156, 156, 156, 156, 156, 156, 156, 165, 165, 165, 165, 165, 165, 165, 165, 165, 173, 173, 173, 173, 173, 173, 173, 173, 181, 181, 181, 181, 181, 181, 181, 181, 189, 189, 189, 189, 189, 189, 189, 189, 198, 198, 198, 198, 198, 198, 198, 198, 198, 206, 206, 206, 206, 206, 206, 206, 206, 214, 214, 214, 214, 214, 214, 214, 214, 222, 222, 222, 222, 222, 222, 222, 222, 231, 231, 231, 231, 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 247, 247, 247, 247, 247, 247, 247, 247, 255, 255, 255, 255];

var bg_color = app.backgroundColor;

var bg_red = parseInt(bg_color.rgb.red + 0.5);
var bg_green = parseInt(bg_color.rgb.green + 0.5);
var bg_blue = parseInt(bg_color.rgb.blue + 0.5);

bg_color.rgb.red = rgb8to5Nearest[bg_red];
bg_color.rgb.green = rgb8to5Nearest[bg_green];
bg_color.rgb.blue = rgb8to5Nearest[bg_blue];

app.backgroundColor = bg_color;


var fg_color = app.foregroundColor;

var fg_red = parseInt(fg_color.rgb.red + 0.5);
var fg_green = parseInt(fg_color.rgb.green + 0.5);
var fg_blue = parseInt(fg_color.rgb.blue + 0.5);

fg_color.rgb.red = rgb8to5Nearest[fg_red];
fg_color.rgb.green = rgb8to5Nearest[fg_green];
fg_color.rgb.blue = rgb8to5Nearest[fg_blue];

app.foregroundColor = fg_color;
}
}
}
}
} catch (e) {}
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Script bugs when launched by notifier

Post by Kukurykus »

No, I can't help this time. I remember when I didn't know there is need of targeting application to use at beggining of code I tricked system changing In file properties the app. Windows has to see, so changed scripts to run in Photoshop. But that was problem as later I had to change it back if I wanted to run them just in ESTK.

And well, I see you handled with writing a script yourself. But I tested it and I'm not sure that was intended but that does not gives expected values like mine :/ though I see you pointed them in the array.