Copy link to clipboard
Copied
Hi,
I have this sample script:
#target photoshop
app.bringToFront();
var dlg = new Window('dialog', 'test');
w = dlg.add('button', undefined, 'cm1',{name:'ok'});
var docRef = app.activeDocument;
w.onClick = run;
dlg.show();
function run(){docRef.activeLayer.mixChannels ([[100,20,-50,00],[30,70,90,00],[-10,-30,-90,00]], false);app.refresh();}
Photoshop CS5 closes the script if I press the button a few times quickly. If I wait a few seconds between button presses it works fine, which makes me thing that Photoshop can not queue the commands. With Photoshop CS3 however, everything is working perfectly, I can press the button as quickly as I like and CS3 just executes it one by one.
Any way to work around this issue???
Thanks.
Copy link to clipboard
Copied
Try this instead of app.refresh(). If it's using a different underlying mechanism, it may avoid the problem you're seeing.
function waitForRedraw() {
function cTID(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
desc.putEnumerated(cTID("Stte"), cTID("Stte"), cTID("RdCm"));
executeAction(cTID("Wait"), desc, DialogModes.NO);
};
Copy link to clipboard
Copied
Thank you, but it does not help. I've found that if I use executeAction() instead of docRef.activeLayer.mixChannels it works! I seems that I have to use everything with executeAction() for now... not my first choice...
Copy link to clipboard
Copied
Is this Mac? Win? Both? Can you give me your system info?
Copy link to clipboard
Copied
Yes. MacBook Pro, Intel Core 2 Duo, 3 GB, Mac OS X 10.6.3 (10D573). Thanks. Haven't tried on PC.
Copy link to clipboard
Copied
Can someone help me with this?
Copy link to clipboard
Copied
I've just tested it on Photoshop CS5 PC and it is working fine. This is a Mac issue only... Bug?
Copy link to clipboard
Copied
It sounds to me that the bug is not with app.refresh but istead with the DOM method mixChannels. And that you have already found a workaround of using the Action Manager API.
Copy link to clipboard
Copied
Thank you Michael, I have omitted the fact that I have encountered this issue on a more general function. Under Mac, pressing the test button of this code quickly a few times in a row will crash the script. If you comment out the "var n = docRef.activeLayer.name;" it will work as intended.
#target photoshop app.bringToFront(); var dlg = new Window('dialog', 'Test'); var docRef = app.activeDocument; dlg.b= dlg.add('button', undefined, 'test',{name:'ok'}); dlg.b.onClick = test; dlg.show(); function test() {
// comment this to make the script work. var n = docRef.activeLayer.name;
waitForRedraw(); } function waitForRedraw() { function cTID(s) { return app.charIDToTypeID(s); }; var desc = new ActionDescriptor(); desc.putEnumerated(cTID("Stte"), cTID("Stte"), cTID("RdCm")); executeAction(cTID("Wait"), desc, DialogModes.NO); };
Copy link to clipboard
Copied
In that case all I can suggest it that you file a bug report if you have not already done so. https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
Copy link to clipboard
Copied
I will take a look at the mac crasher but it is a problem on windws and a problem in CS4 as far as I can tell. I would recommend you disable your button so the user can only press it once. Here is a modified script to show more of what is going on. On windows I am getting the script to stop for no apparent reason (the actual reason is a stack overflow). On mac my suspssion is that the stack overflow is crashing us instead of erroring out semi correctly! You can try all combinations of the two flags at the top to see the behavior differences. And you can really see how long waitForRefresh is taking so use it wisely!
// http://forums.adobe.com/message/2873601#2873601 {
#target photoshop
app.bringToFront();
try
var buttonDisable = true;
var blockingOn = false;
var redraws = 0;
var blocked = 0;
if (documents.length == 0) {
documents.add();
}
var dlg = new Window('dialog', 'Test');
var docRef = app.activeDocument;
dlg.b= dlg.add('button', undefined, 'test',{name:'ok'});
dlg.b.onClick = test;
dlg.show();
function test()
{
if (buttonDisable) {
dlg.b.enabled = false;
}
// comment this to make the script work.
var n = docRef.activeLayer.name;
if (blockingOn) {
if ($.stack.search('waitForRedraw()') == -1) {
waitForRedraw();
redraws++;
} else {
blocked++;
}
} else {
waitForRedraw();
redraws++;
}
if (buttonDisable) {
dlg.b.enabled = true;
}
}
function waitForRedraw() {
function cTID(s) { return app.charIDToTypeID(s); };
var desc = new ActionDescriptor();
desc.putEnumerated(cTID("Stte"), cTID("Stte"), cTID("RdCm"));
executeAction(cTID("Wait"), desc, DialogModes.NO);
}
}
catch(e) {
alert(e + ":" + e.line);
}
alert(blocked + ":" + redraws);
Copy link to clipboard
Copied
A real stack overflow should crash. On Windows, I suspect that some of our last-ditch error handling is just able to recover better.
If it's a stack overflow in JavaScript - that should just return an error.
Copy link to clipboard
Copied
Thank you Tom for the most helpful response. Disabling the button does improve the situation, but is seems that waitForRedraw takes quite a bit longer than I expected, where the button only enabled a few seconds after the "Action" was executed. It does not provide a very good user experience .
Any way to make it work quicker maybe?
Copy link to clipboard
Copied
I don't know of anything that would make it work quicker. Forcing everyone to repaint is going to be slow. Photoshop was designed to run actions as fast as possible. The theory was you are going to run something that you are going to be sipping coffee and reading email while Photoshop is churning in the background and you don't really care about the intermediate steps. Just the end result. Wait for redraw is an attempt to change the design and you are now telling Photoshop, please run slow enough so I can see the intermediate steps. You basically can't have it both ways.