I just need a script that if the height is greater than or equal to its width then do script HeightReframe.jsx, if Width is greater than its height then do the script. WidthReframe.jsx
I had previously made a post but I made it more complicated than I needed. I've included the scripts I would want it to run I assume quicker to paste them within the whole script.
Also I found this post, bb/viewtopic.php?f=9&t=2469&p=10591&hil ... vas#p10591 but could not begin to get it to work I'm running CS5 if that should make any difference?
Many Thanks
Matt
Code: Select all#target photoshop
//
// HeightReframe.jsx
//
//
// Generated Fri Oct 05 2012 09:15:27 GMT+0100
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== HeightReframe ==============
//
function HeightReframe() {
// Canvas Size
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putBoolean(cTID('Rltv'), true);
desc1.putUnitDouble(cTID('Hght'), cTID('#Prc'), 5.00000000000001);
desc1.putEnumerated(cTID('Vrtc'), cTID('VrtL'), cTID('Cntr'));
executeAction(sTID('canvasSize'), desc1, dialogMode);
};
// Image Size
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 1530.00287364683);
executeAction(sTID('imageSize'), desc1, dialogMode);
};
// Canvas Size
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 1020);
desc1.putEnumerated(cTID('Hrzn'), cTID('HrzL'), cTID('Cntr'));
executeAction(sTID('canvasSize'), desc1, dialogMode);
};
// Select
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "BACKGROUND");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
executeAction(cTID('slct'), desc1, dialogMode);
};
// Fill
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('Usng'), cTID('FlCn'), cTID('BckC'));
executeAction(cTID('Fl '), desc1, dialogMode);
};
// Select
function step6(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "Main Image");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
executeAction(cTID('slct'), desc1, dialogMode);
};
step1(); // Canvas Size
step2(); // Image Size
step3(); // Canvas Size
step4(); // Select
step5(); // Fill
step6(); // Select
};
//=========================================
// HeightReframe.main
//=========================================
//
HeightReframe.main = function () {
HeightReframe();
};
HeightReframe.main();
// EOF
"HeightReframe.jsx"
// EOF
____________________________________________
Code: Select all#target photoshop
//
// WidthReframe.jsx
//
//
// Generated Fri Oct 05 2012 09:15:39 GMT+0100
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== WidthReframe ==============
//
function WidthReframe() {
// Canvas Size
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putBoolean(cTID('Rltv'), true);
desc1.putUnitDouble(cTID('Wdth'), cTID('#Prc'), 5);
desc1.putEnumerated(cTID('Hrzn'), cTID('HrzL'), cTID('Cntr'));
executeAction(sTID('canvasSize'), desc1, dialogMode);
};
// Image Size
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Wdth'), cTID('#Rlt'), 1020.00265008187);
executeAction(sTID('imageSize'), desc1, dialogMode);
};
// Canvas Size
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('Hght'), cTID('#Rlt'), 1530);
desc1.putEnumerated(cTID('Vrtc'), cTID('VrtL'), cTID('Cntr'));
executeAction(sTID('canvasSize'), desc1, dialogMode);
};
// Select
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "BACKGROUND");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
executeAction(cTID('slct'), desc1, dialogMode);
};
// Fill
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putEnumerated(cTID('Usng'), cTID('FlCn'), cTID('BckC'));
executeAction(cTID('Fl '), desc1, dialogMode);
};
step1(); // Canvas Size
step2(); // Image Size
step3(); // Canvas Size
step4(); // Select
step5(); // Fill
};
//=========================================
// WidthReframe.main
//=========================================
//
WidthReframe.main = function () {
WidthReframe();
};
WidthReframe.main();
// EOF
"WidthReframe.jsx"
// EOF
If Height is ≥ width then do A else do B?
-
pfaffenbichler
If Height is ≥ width then do A else do B?
You mean something like this? (You could wrap your Scripts in functions and replace the alerts.)
Code: Select all#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.width > myDocument.height) {alert ("landscape")}
else {alert ("portrait")}
};
Code: Select all#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.width > myDocument.height) {alert ("landscape")}
else {alert ("portrait")}
};
-
Mcquiff
If Height is ≥ width then do A else do B?
I've worked out how to do it in Applescript and this is what I would like to do but I need it in js so that I can run it from within photoshop with a hotkey
tell application "Adobe Photoshop CS5.1"
activate
set ruler units of settings to point units
tell current document
--Set Ratio Dimensions Here
set tHeight to 1530 --Change this line for your Height
set tWidth to 1020 --Change this line for your Width
set BorderIncrease to 5 -- this is your border percentage
--change none of the below details
set {height:aHeight, width:aWidth, resolution:tReso} to it
set targetRatio to (tHeight / tWidth)
set borderHeight to ((tHeight / 100) * BorderIncrease) + tHeight
set borderWidth to ((tWidth / 100) * BorderIncrease) + tWidth
set actualRatio to aHeight / aWidth
if actualRatio ≤ targetRatio then
resize image width tWidth
resize canvas height tHeight anchor position middle center
resize canvas width borderWidth anchor position middle center -- this adds 5% border
resize image width tWidth
resize canvas height tHeight anchor position middle center
else
resize image height tHeight
resize canvas width tWidth anchor position middle center
resize canvas height borderHeight anchor position middle center -- this adds 5% border
resize image height tHeight
resize canvas width tWidth anchor position middle center
end if
end tell
end tell
tell application "Adobe Photoshop CS5.1"
activate
set ruler units of settings to point units
tell current document
--Set Ratio Dimensions Here
set tHeight to 1530 --Change this line for your Height
set tWidth to 1020 --Change this line for your Width
set BorderIncrease to 5 -- this is your border percentage
--change none of the below details
set {height:aHeight, width:aWidth, resolution:tReso} to it
set targetRatio to (tHeight / tWidth)
set borderHeight to ((tHeight / 100) * BorderIncrease) + tHeight
set borderWidth to ((tWidth / 100) * BorderIncrease) + tWidth
set actualRatio to aHeight / aWidth
if actualRatio ≤ targetRatio then
resize image width tWidth
resize canvas height tHeight anchor position middle center
resize canvas width borderWidth anchor position middle center -- this adds 5% border
resize image width tWidth
resize canvas height tHeight anchor position middle center
else
resize image height tHeight
resize canvas width tWidth anchor position middle center
resize canvas height borderHeight anchor position middle center -- this adds 5% border
resize image height tHeight
resize canvas width tWidth anchor position middle center
end if
end tell
end tell