// Ask user for input by showing prompt box and save inputted value to variable:
var realsize = prompt("How high do you need your image in pixels?", 0, "Jimmy McIntyre Super-Duper Sharpen/Resize");

//create new window
var idDplc = charIDToTypeID( "Dplc" );
    var desc237 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref124 = new ActionReference();
        var idDcmn = charIDToTypeID( "Dcmn" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idFrst = charIDToTypeID( "Frst" );
        ref124.putEnumerated( idDcmn, idOrdn, idFrst );
    desc237.putReference( idnull, ref124 );
    var idNm = charIDToTypeID( "Nm  " );
    desc237.putString( idNm, "" );
executeAction( idDplc, desc237, DialogModes.NO );

// temp layer
var idMk = charIDToTypeID( "Mk  " );
    var desc238 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref125 = new ActionReference();
        var idAdjL = charIDToTypeID( "AdjL" );
        ref125.putClass( idAdjL );
    desc238.putReference( idnull, ref125 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc239 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc240 = new ActionDescriptor();
            var idpresetKind = stringIDToTypeID( "presetKind" );
            var idpresetKindType = stringIDToTypeID( "presetKindType" );
            var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
            desc240.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
        var idCrvs = charIDToTypeID( "Crvs" );
        desc239.putObject( idType, idCrvs, desc240 );
    var idAdjL = charIDToTypeID( "AdjL" );
    desc238.putObject( idUsng, idAdjL, desc239 );
executeAction( idMk, desc238, DialogModes.NO );

// flatten
var idFltI = charIDToTypeID( "FltI" );
executeAction( idFltI, undefined, DialogModes.NO );

// name BK layer
var idsetd = charIDToTypeID( "setd" );
    var desc241 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref126 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref126.putEnumerated( idLyr, idOrdn, idTrgt );
    desc241.putReference( idnull, ref126 );
    var idT = charIDToTypeID( "T   " );
        var desc242 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc242.putString( idNm, """Not Sharpened""" );
    var idLyr = charIDToTypeID( "Lyr " );
    desc241.putObject( idT, idLyr, desc242 );
executeAction( idsetd, desc241, DialogModes.NO );

 
//calculate size  
var mydoc = app.activeDocument;
var realsizefin = (realsize * 1.67);

mydoc.resizeImage(undefined, UnitValue(realsizefin, "px"), 300, ResampleMethod.BICUBIC);

// =======================================================
var idCpTL = charIDToTypeID( "CpTL" );
executeAction( idCpTL, undefined, DialogModes.NO );

//dup mask rename
var idMk = charIDToTypeID( "Mk  " );
    var desc243 = new ActionDescriptor();
    var idNw = charIDToTypeID( "Nw  " );
    var idChnl = charIDToTypeID( "Chnl" );
    desc243.putClass( idNw, idChnl );
    var idAt = charIDToTypeID( "At  " );
        var ref127 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idMsk = charIDToTypeID( "Msk " );
        ref127.putEnumerated( idChnl, idChnl, idMsk );
    desc243.putReference( idAt, ref127 );
    var idUsng = charIDToTypeID( "Usng" );
    var idUsrM = charIDToTypeID( "UsrM" );
    var idRvlA = charIDToTypeID( "RvlA" );
    desc243.putEnumerated( idUsng, idUsrM, idRvlA );
executeAction( idMk, desc243, DialogModes.NO );

//below is to remove 1px outline

// =======================================================

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc244 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref128 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idRGB = charIDToTypeID( "RGB " );
        ref128.putEnumerated( idChnl, idChnl, idRGB );
    desc244.putReference( idnull, ref128 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc244.putBoolean( idMkVs, false );
executeAction( idslct, desc244, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc245 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref129 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref129.putEnumerated( idLyr, idOrdn, idTrgt );
    desc245.putReference( idnull, ref129 );
    var idT = charIDToTypeID( "T   " );
        var desc246 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc246.putString( idNm, """Sharpened""" );
    var idLyr = charIDToTypeID( "Lyr " );
    desc245.putObject( idT, idLyr, desc246 );
executeAction( idsetd, desc245, DialogModes.NO );

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc244 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref128 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idRGB = charIDToTypeID( "RGB " );
        ref128.putEnumerated( idChnl, idChnl, idRGB );
    desc244.putReference( idnull, ref128 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc244.putBoolean( idMkVs, false );
executeAction( idslct, desc244, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc245 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref129 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref129.putEnumerated( idLyr, idOrdn, idTrgt );
    desc245.putReference( idnull, ref129 );
    var idT = charIDToTypeID( "T   " );
        var desc246 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc246.putString( idNm, """Sharpened""" );
    var idLyr = charIDToTypeID( "Lyr " );
    desc245.putObject( idT, idLyr, desc246 );
executeAction( idsetd, desc245, DialogModes.NO );

// sharp
var idShrp = charIDToTypeID( "Shrp" );
executeAction( idShrp, undefined, DialogModes.NO );

// dup
var idCpTL = charIDToTypeID( "CpTL" );
executeAction( idCpTL, undefined, DialogModes.NO );

// rename
var idsetd = charIDToTypeID( "setd" );
    var desc247 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref130 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref130.putEnumerated( idLyr, idOrdn, idTrgt );
    desc247.putReference( idnull, ref130 );
    var idT = charIDToTypeID( "T   " );
        var desc248 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc248.putString( idNm, """Sharpened More""" );
    var idLyr = charIDToTypeID( "Lyr " );
    desc247.putObject( idT, idLyr, desc248 );
executeAction( idsetd, desc247, DialogModes.NO );

// sharp
var idShrp = charIDToTypeID( "Shrp" );
executeAction( idShrp, undefined, DialogModes.NO );

// dup
var idCpTL = charIDToTypeID( "CpTL" );
executeAction( idCpTL, undefined, DialogModes.NO );

// rename
var idsetd = charIDToTypeID( "setd" );
    var desc249 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref131 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref131.putEnumerated( idLyr, idOrdn, idTrgt );
    desc249.putReference( idnull, ref131 );
    var idT = charIDToTypeID( "T   " );
        var desc250 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc250.putString( idNm, """Extra Sharp For Larger Images""" );
    var idLyr = charIDToTypeID( "Lyr " );
    desc249.putObject( idT, idLyr, desc250 );
executeAction( idsetd, desc249, DialogModes.NO );

// sharp
var idShrp = charIDToTypeID( "Shrp" );
executeAction( idShrp, undefined, DialogModes.NO );


// hide
var idHd = charIDToTypeID( "Hd  " );
    var desc251 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var list83 = new ActionList();
            var ref132 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref132.putEnumerated( idLyr, idOrdn, idTrgt );
        list83.putReference( ref132 );
    desc251.putList( idnull, list83 );
executeAction( idHd, desc251, DialogModes.NO );

//final resize
mydoc.resizeImage(undefined, UnitValue(realsize, "px"), 300, ResampleMethod.BICUBIC);

//rseize window
function viewActualPixels() {
	var desc = new ActionDescriptor();
	var ref = new ActionReference();
	ref.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ActP'));
	desc.putReference(cTID('null'), ref);
	executeAction(cTID('slct'), desc, DialogModes.NO);
}

function cTID(s) {return app.charIDToTypeID(s);}

viewActualPixels();

//The rest is to remove 1px outline

// =======================================================
var idslct = charIDToTypeID( "slct" );
    var desc143 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref87 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref87.putName( idLyr, "Not Sharpened" );
    desc143.putReference( idnull, ref87 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc143.putBoolean( idMkVs, false );
    var idLyrI = charIDToTypeID( "LyrI" );
        var list66 = new ActionList();
        list66.putInteger( 20 );
    desc143.putList( idLyrI, list66 );
executeAction( idslct, desc143, DialogModes.NO );

// =======================================================
var idCpTL = charIDToTypeID( "CpTL" );
executeAction( idCpTL, undefined, DialogModes.NO );

// =======================================================
var idsetd = charIDToTypeID( "setd" );
    var desc144 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref88 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref88.putEnumerated( idLyr, idOrdn, idTrgt );
    desc144.putReference( idnull, ref88 );
    var idT = charIDToTypeID( "T   " );
        var desc145 = new ActionDescriptor();
        var idNm = charIDToTypeID( "Nm  " );
        desc145.putString( idNm, """ns temp""" );
    var idLyr = charIDToTypeID( "Lyr " );
    desc144.putObject( idT, idLyr, desc145 );
executeAction( idsetd, desc144, DialogModes.NO );

// =======================================================
var idMrgtwo = charIDToTypeID( "Mrg2" );
    var desc146 = new ActionDescriptor();
executeAction( idMrgtwo, desc146, DialogModes.NO );

//Change to RGB Colour Profile


var r = confirm("Do you want to convert the colour profile to sRGB (recommended for the Web)?");
if (r == true) {
    app.activeDocument.convertProfile( "sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true );  
    alert("Sharpening Complete");  }

else {
   alert("Sharpening Complete");  }

    





