Hello Sir @c.pfaffenbichler
I tried to fix the scripts for Unsharp Mask but I don't know where I'm going wrong, the usharp mask scripts are unusable, please help me
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (hasSelection() == true) {
var theBounds = activeDocument.selection.bounds;
var theWidth = theBounds[2] - theBounds[0];
var theHeight = theBounds[3] - theBounds[1];
var theValue = Math.max(theWidth, theHeight) * 0.021;
UnsharpMask (theValue)
};
app.preferences.rulerUnits = originalRulerUnits;
};
////// UnsharpMask //////
function UnsharpMask (theAmount, theRadius, theThreshold) {
try {
var desc1 = new ActionDescriptor();
desc1.putUnitDouble( charIDToTypeID( "Amnt " ), charIDToTypeID( "#Prc" ), theAmount );
desc1.putUnitDouble( charIDToTypeID( "Rds " ), charIDToTypeID( "#Pxl" ), theRadius );
desc1.putInteger( charIDToTypeID( "Thsh" ), theThreshold );
executeAction( stringIDToTypeID( "UnsharpMask" ), desc1, DialogModes.NO );
app.refresh();
} catch (e) {}
};
////// check for selection //////
function hasSelection(){
var ref10 = new ActionReference();
ref10.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var docDesc = executeActionGet(ref10);
return docDesc.hasKey(stringIDToTypeID("selection"));
};
For one thing a function that takes three arguments should be fed three arguments.
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (hasSelection() == true) {
var theBounds = activeDocument.selection.bounds;
var theWidth = theBounds[2] - theBounds[0];
var theHeight = theBounds[3] - theBounds[1];
var theValue = Math.max(theWidth, theHeight) * 0.021;
unsharpMask (120, theValue, 10)
};
app.preferences.rulerUnits = originalRulerUnits;
};
////// unsharp mask //////
function unsharpMask (amount, radius, threshold) {
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( idAmnt = charIDToTypeID( "Amnt" ), charIDToTypeID( "#Prc" ), amount );
desc2.putUnitDouble( charIDToTypeID( "Rds " ), charIDToTypeID( "#Pxl" ), radius );
desc2.putInteger( charIDToTypeID( "Thsh" ), threshold );
executeAction( charIDToTypeID( "UnsM" ), desc2, DialogModes.NO);
};
////// check for selection //////
function hasSelection(){
var ref10 = new ActionReference();
ref10.putProperty(stringIDToTypeID("property"), stringIDToTypeID("selection"));
ref10.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var docDesc = executeActionGet(ref10);
return docDesc.hasKey(stringIDToTypeID("selection"));
};