Copy link to clipboard
Copied
I am using a Mac but the script works for both Mac and PC just fine for any Photoshop CS3 or above.
Basically I'm trying to use three different actions.
1 - if the picture is more than 2000 px wide or tall it will run action "Approve"
2 - if the picture is between 1200 and 1999 px - it will run the action "Acceptable"
3 - if the picture is lower than 1199 px - it will run the action "Reject"
Hopefully this makes sense on what I want.
SCRIPT STARTS BELOW.
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.INCHES;
var Web_Action = 'NWS-APPROVE';
var Approve = 'NWS-APPROVE';
var Acceptable = 'NWS-APPROVE';
var Rejected = 'NWS-APPROVE';
//this will get rid of extra alpha channels
//docRef = app.activeDocument;
//var i=4;
//while(docRef.channels.length>4)
//{
// docRef.channels.remove();
//}
//activeDocument.save();
if(activeDocument.width>=3000|| activeDocument.height>=3000)
{
app.doAction ("Approve", "NWS-APPROVE");
// alert('small'); // or issue a message
//activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
if(activeDocument.width<=1500|| activeDocument.height<=1500)
{
app.doAction ("Acceptable", "NWS-APPROVE");
// alert('small'); // or issue a message
//activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
if(activeDocument.width<=1200|| activeDocument.height<=1200)
{
app.doAction ("Rejected", "NWS-APPROVE");
// alert('small'); // or issue a message
//activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
preferences.rulerUnits = strtRulerUnits;
//end
So after reading some more things. This one works!!! the ".as('px') is needed for the program to recognize the specific sizes correctly.
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.INCHES;
//This top script allows the script to be recorded on Photoshop as a action.
var longestSide;
if (activeDocument.height > activeDocument.width) {
longestSide=activeDocument.height;
}else{
longestSide=activeDocument.width;
}
if (longestSide.as(
...Copy link to clipboard
Copied
preferences.rulerUnits = Units.INCHES; ???????????????????????????????????????
try using PIXELS
Copy link to clipboard
Copied
your algorithm is not correct. You have written something like this :
if(width>=3000 || height>=3000) -> Approve
if(width<=1500 || height<=1500) -> Acceptable
if(width<=1200 || height<=1200) ->Rejected
Two errors :
If width has a value of 2200 : no action.
if width has a value of 700 : the size is Acceptable then Rejected (2 actions)
You should classify the size of your document in a variable first and launch the required action after.
Something like :
var size=1;
if (width<3000) size=2;
if (width<1500) size=3;
Now you know the size of your document. You can launch an action with a simple switch (size) selector.
Excuse my poor English.
Copy link to clipboard
Copied
How would I write the variable first and also how does that affect how I write what action is ran? Could you write up a sample for me? It makes more sense if I see a visual sample.
Copy link to clipboard
Copied
It looks like what your wrote looks ok. What do you mean that it is still running on rejected? Do you have more of the script that runs after the if statement? The last else should catch anything that is smaller than 1200px. If you don't want the script to prceed past that, put other parts of the script in functions that are just called from the first two if statements. And I'm not sure what you mean by the first variable. In my script, the first variable is doc that is the active document. Here's what you can do to with the functions:
#target photoshop
var doc = activeDocument;
var longSide = Math.max(doc.width,doc.height);
if(longSide>200){do2000()}
else if(longSide>=1200){do1200()};
else{doReject()}
//no code that's not in a function after this point or it will run with rejected.
function do2000(){//code here
doMore()
}
function do1200(){//code here
doMore()
}
function doReject(){//reject code here
}
function doMore(){//code you want to run after sorting size do to to every image except rejects
}
Copy link to clipboard
Copied
I will go a step further than what Michael said, Trying to set an script to have both the height and width used in a calculation will be difficult. I'm guessing you want those limits such as the 2000px to be the longest side. It would be easier to set up separate routines for vertical and horizontal images. Is the min value for the longest side too? If you're looking just for dimensions on the longest side then something like:
var doc=activeDocument;
var longSide = Math.max(doc.width,doc.height)
if(longSide>2000){//your code here
}
else if(longSide>=1200){//more code here
{
else{//this will catch all the stuff below 1200
}
Copy link to clipboard
Copied
Chuck I like your coding and it does make sense but it is still running on rejected. This is what I have down below
var doc=activeDocument;
var longSide = Math.max(doc.width,doc.height)
if (longSide>3000)
{
app.doAction ("Approve", "NWS-APPROVE");
// alert('small'); // or issue a message
//activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
else if(longSide>=1200)
{
app.doAction ("Acceptable", "NWS-APPROVE");
// alert('small'); // or issue a message
//activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
else
{
app.doAction ("Rejected", "NWS-APPROVE");
// alert('small'); // or issue a message
//activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
Copy link to clipboard
Copied
So after reading some more things. This one works!!! the ".as('px') is needed for the program to recognize the specific sizes correctly.
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.INCHES;
//This top script allows the script to be recorded on Photoshop as a action.
var longestSide;
if (activeDocument.height > activeDocument.width) {
longestSide=activeDocument.height;
}else{
longestSide=activeDocument.width;
}
if (longestSide.as('px') < 1200)
{
app.doAction ("Rejected", "NWS-APPROVE");
}
else if (longestSide.as('px') <= 1800)
{
app.doAction ("Acceptable", "NWS-APPROVE");
}
else
{
app.doAction ("Approve", "NWS-APPROVE");
}
preferences.rulerUnits = strtRulerUnits;
//end