Functions for Photoshop

Resize selection

function resizeSelection(horizontal, vertical){
	var strtRulerUnits = app.preferences.rulerUnits;
	var strtTypeUnits = app.preferences.typeUnits;
	app.preferences.rulerUnits = Units.PIXELS;
	app.preferences.typeUnits = TypeUnits.PIXELS;
	var SB = activeDocument.selection.bounds;
	var Height = SB[3].value - SB[1].value;
	var Width = SB[2].value - SB[0].value;
	var onePixH = 100/Height;
	var onePixW = 100/Width;
	var newWidth = onePixW * horizontal;
	var newHeight = onePixH * vertical;
	activeDocument.selection.resize( newWidth , newHeight, AnchorPosition.MIDDLECENTER  );
	app.preferences.rulerUnits = strtRulerUnits;
	app.preferences.typeUnits = strtTypeUnits;
}

Save as JPEG

function saveJPEG( doc, saveFile, qty ) {
     var saveOptions = new JPEGSaveOptions( );
     saveOptions.embedColorProfile = true;
     saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
     saveOptions.matte = MatteType.NONE;
     saveOptions.quality = qty; 
     doc.saveAs( saveFile, saveOptions, true );
}


saveJPEG( app.activeDocument, new File('~/Desktop/sample.jpg'), 10 );

Fit image by Xbytor

function fitImage(doc, width, height) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

app.activeDocument = doc;
var desc = new ActionDescriptor();
desc.putUnitDouble( cTID('Wdth'), cTID('#Pxl'), width );
desc.putUnitDouble( cTID('Hght'), cTID('#Pxl'), height );

var fitId = sTID('3caa3434-cb67-11d1-bc43-0060b0a13dc4');
executeAction(fitId , desc, DialogModes.NO );
};

function main() {
if (app.documents.length == 0) {
alert ("No Open Documents, Script will terminate");
return;
}

var ru = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

var doc = app.activeDocument;

try {
var s = prompt("Largest New Dimension (pixels)",
doc.height.value,
"Dimension");

var lrgdim = Number(s);
if (isNaN(lrgdim) || lrgdim < 0) {
alert("Bad dimension specified: " + s);
}

var s = prompt ("New Resolution (ppi)", 300, "Resolution");
var resolution = Number(s);
if (isNaN(resolution) || resolution < 0) {
alert("Bad dimension specified: " + s);
}

doc.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
fitImage(doc, lrgdim, lrgdim);
doc.resizeImage(undefined, undefined, resolution, ResampleMethod.NONE);

} finally {
app.preferences.rulerUnits = ru;
}
};

main();

Wait for redraw

A helper function for debugging It also helps the user see what is going on. if you turn it off for this example you get a flashing cursor for a number time

function WaitForRedraw()
{
	var eventWait = charIDToTypeID("Wait")
	var enumRedrawComplete = charIDToTypeID("RdCm")
	var typeState = charIDToTypeID("Stte")
	var keyState = charIDToTypeID("Stte")
	var desc = new ActionDescriptor()
	desc.putEnumerated(keyState, typeState, enumRedrawComplete)
	executeAction(eventWait, desc, DialogModes.NO)
}