Skip to main content
Participating Frequently
September 8, 2022
Answered

File - Automate - Batch

  • September 8, 2022
  • 1 reply
  • 527 views

I would like to create a Batch Action from an Action that changes a photo's HUE value by 1. So that I can create 360 different PNG files.

Is that possible?

In essence the HUE value is a variable that increased by 1 each time it cycles through the Action.

This topic has been closed for replies.
Correct answer jazz-y
var s2t = stringIDToTypeID,
	saveOptions;
try {
	(d = new ActionDescriptor()).putObject(s2t("as"), s2t("PNGFormat"), new ActionDescriptor());
	var saveOptions = executeAction(s2t("save"), d, DialogModes.ALL);
} catch (e) { }
if (saveOptions) {
	var savePath = saveOptions.getPath(s2t('in')).path,
		saveName = saveOptions.getPath(s2t('in')).name.replace(/\.[0-9a-z]+$/, '');
	doProgress('', 'saveToPng()');
	function saveToPng() {
		(r = new ActionReference()).putClass(s2t("adjustmentLayer"));
		(d = new ActionDescriptor()).putReference(s2t("null"), r);
		(d2 = new ActionDescriptor()).putObject(s2t("type"), s2t("hueSaturation"), new ActionDescriptor());
		d.putObject(s2t("using"), s2t("adjustmentLayer"), d2);
		executeAction(s2t("make"), d, DialogModes.NO);
		for (var i = 0; i <= 360; i++) {
			updateProgress(i, 360);
			(r = new ActionReference()).putEnumerated(s2t("adjustmentLayer"), s2t("ordinal"), s2t("targetEnum"));
			(d = new ActionDescriptor()).putReference(s2t("null"), r);
			(d1 = new ActionDescriptor()).putEnumerated(s2t("presetKind"), s2t("presetKindType"), s2t("presetKindCustom"));
			(d2 = new ActionDescriptor()).putInteger(s2t("hue"), -180 + i);
			d2.putInteger(s2t("saturation"), 0);
			d2.putInteger(s2t("lightness"), 0);
			(l = new ActionList()).putObject(s2t("hueSatAdjustmentV2"), d2);
			d1.putList(s2t("adjustment"), l);
			d.putObject(s2t("to"), s2t("hueSaturation"), d1);
			executeAction(s2t("set"), d, DialogModes.NO);
			changeProgressText('saving file: ' + saveName + ' ' + -180 + i + '.png');
			saveOptions.putPath(s2t('in'), new File(savePath + '/' + saveName + ' ' + (- 180 + i) + '.png'))
			executeAction(s2t("save"), saveOptions, DialogModes.NO);
		}
		(r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
		(d = new ActionDescriptor()).putReference(s2t("null"), r);
		executeAction(s2t("delete"), d, DialogModes.NO);
	}
}

1 reply

Legend
September 8, 2022

This can be done using batch processing and actions, but with a some problems, so it's easier with a script:

 

var s2t = stringIDToTypeID,
	saveOptions;
try {
	(d = new ActionDescriptor()).putObject(s2t("as"), s2t("PNGFormat"), new ActionDescriptor());
	var saveOptions = executeAction(s2t("save"), d, DialogModes.ALL);
} catch (e) { }
if (saveOptions) {
	var savePath = saveOptions.getPath(s2t('in')).path,
		saveName = saveOptions.getPath(s2t('in')).name.replace(/\.[0-9a-z]+$/, ''),
		offset = 0;
	doProgress('', 'saveToPng()');
	function saveToPng() {
		for (var i = 0; i < 360; i++) {
			updateProgress(i + 1, 360);
			(d = new ActionDescriptor()).putEnumerated(s2t("presetKind"), s2t("presetKindType"), s2t("presetKindCustom"));
			d.putBoolean(s2t("colorize"), false);
			(d1 = new ActionDescriptor()).putInteger(s2t("hue"), 1);
			d1.putInteger(s2t("saturation"), 0);
			d1.putInteger(s2t("lightness"), 0);
			(l = new ActionList()).putObject(s2t("hueSatAdjustmentV2"), d1);
			d.putList(s2t("adjustment"), l);
			executeAction(s2t("hueSaturation"), d, DialogModes.NO);
			changeProgressText('saving file: ' + saveName + ' ' + ++offset + '.png');
			saveOptions.putPath(s2t('in'), new File(savePath + '/' + saveName + ' ' + offset + '.png'))
			executeAction(s2t("save"), saveOptions, DialogModes.NO);
		}
	}
}

 

Leon1549Author
Participating Frequently
September 8, 2022

- simply awesome!!!!!!!! you are the best!!!

as with any request - one simple change if possible (if it makes sense)

since HUE starts at   -180    and ends at    180 --- how can this script be modified for that?

Or does it already ccount for that?

Many kudos

Leon

 

jazz-yCorrect answer
Legend
September 8, 2022
var s2t = stringIDToTypeID,
	saveOptions;
try {
	(d = new ActionDescriptor()).putObject(s2t("as"), s2t("PNGFormat"), new ActionDescriptor());
	var saveOptions = executeAction(s2t("save"), d, DialogModes.ALL);
} catch (e) { }
if (saveOptions) {
	var savePath = saveOptions.getPath(s2t('in')).path,
		saveName = saveOptions.getPath(s2t('in')).name.replace(/\.[0-9a-z]+$/, '');
	doProgress('', 'saveToPng()');
	function saveToPng() {
		(r = new ActionReference()).putClass(s2t("adjustmentLayer"));
		(d = new ActionDescriptor()).putReference(s2t("null"), r);
		(d2 = new ActionDescriptor()).putObject(s2t("type"), s2t("hueSaturation"), new ActionDescriptor());
		d.putObject(s2t("using"), s2t("adjustmentLayer"), d2);
		executeAction(s2t("make"), d, DialogModes.NO);
		for (var i = 0; i <= 360; i++) {
			updateProgress(i, 360);
			(r = new ActionReference()).putEnumerated(s2t("adjustmentLayer"), s2t("ordinal"), s2t("targetEnum"));
			(d = new ActionDescriptor()).putReference(s2t("null"), r);
			(d1 = new ActionDescriptor()).putEnumerated(s2t("presetKind"), s2t("presetKindType"), s2t("presetKindCustom"));
			(d2 = new ActionDescriptor()).putInteger(s2t("hue"), -180 + i);
			d2.putInteger(s2t("saturation"), 0);
			d2.putInteger(s2t("lightness"), 0);
			(l = new ActionList()).putObject(s2t("hueSatAdjustmentV2"), d2);
			d1.putList(s2t("adjustment"), l);
			d.putObject(s2t("to"), s2t("hueSaturation"), d1);
			executeAction(s2t("set"), d, DialogModes.NO);
			changeProgressText('saving file: ' + saveName + ' ' + -180 + i + '.png');
			saveOptions.putPath(s2t('in'), new File(savePath + '/' + saveName + ' ' + (- 180 + i) + '.png'))
			executeAction(s2t("save"), saveOptions, DialogModes.NO);
		}
		(r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
		(d = new ActionDescriptor()).putReference(s2t("null"), r);
		executeAction(s2t("delete"), d, DialogModes.NO);
	}
}