After a lot of hit and trials, I came up with this:
//Fake Duotone in InDesign
//Edited by: Masood Ahmad, 29th September 2017
//Original Script created by: Ari S. - designerjoe@outlook.com
app.scriptPreferences.enableRedraw = false;
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Image Manipulation Script");
function main(){
try{
var mySelection = app.selection[0];
var bottomObject = mySelection;
var topObject = bottomObject.duplicate();
var midObject = bottomObject.duplicate();
topObject.transparencySettings.blendingSettings.blendMode = BlendMode.LUMINOSITY;
midObject.transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY;
bottomObject.transparencySettings.blendingSettings.blendMode = BlendMode.NORMAL;
// Find Duotone swatch position
var myDoc = app.activeDocument;
var mySwatches = myDoc.swatches;
var swatchesLength = mySwatches.length;
for (i=0;i<swatchesLength;i++) {
if (mySwatches[i].name == "duotone" || mySwatches[i].name == "Duotone") {
var duotoneSwatch = mySwatches[i];
bottomObject.fillColor = duotoneSwatch;
}
}
// Check if Duotone swatch is defined
if (duotoneSwatch == undefined) {
//alert("Please create a Duotone swatch");
var myColor = myDoc.colors.add();
myColor.colorValue = [75,5,100,0];
myColor.name = "Duotone";
bottomObject.fillColor = myColor;
}
try {
var myGroup = bottomObject.parent.groups.add ([bottomObject, midObject, topObject]);
app.select(myGroup);
}
catch (myError) {
alert("could not group successfully");
}
}
catch (myError){
alert("Make sure you selected a graphic frame");
}
}
The scripts works well and duly checks, create and apply the Duotone swatch.
The only part remaining in the script is to:
1) Delete the image (content) from the bottomObject i.e. keep the bottom frame but delete its content image.
Last but not the least, clean-up the script to avoid unnecessary codes.
Thanks in advance.