Skip to main content
Participant
September 11, 2021
Question

Check document profile, mode and bit depth using scripts

  • September 11, 2021
  • 5 replies
  • 252 views

Hello,

Is there a way to check document's profile, mode and bit depth using scripts? I know it is possible to chage it using:

app.activeDocument.changeMode
app.activeDocument.convertProfile
app.activeDocument.convertBitDepth

but I want to check it first, so basically something like:

if(app.activeDocument.Profile !== "Adobe RGB (1998)") {
var result = confirm ("Wrong color profile. Do you want to change it?", false);
...(rest of the code here)...
}

but this doesn't seem to work.

Any help will be appreciated! Thank you in advance.

This topic has been closed for replies.

5 replies

JJMack
Community Expert
Community Expert
September 11, 2021

Document Info available.

var param = get_param();   
// examples   
//alert(obj_to_str(param), " options");  
info =obj_to_str(param);   
  
function obj_to_str(obj){
    var str = ""; 
    for (var p in obj) {	
        if(obj.hasOwnProperty(p)) {
            try{str+=p+"::"+obj[p]+"\n";}
            catch(e){};
        }
    }		
    logInfo( str);  
    return str;
}   

//////////////////////////////////////////////////////////////////   
  
function get_param() {   
    try {   
        var r = new ActionReference();   
        r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));   
        var d = executeActionGet(r);   
        var ret = new Object();   
        for (var i = 0; i < d.count; i++) {   
            var key = d.getKey(i);   
            var type = d.getType(key);   
            var val = undefined;   
            switch (type) {   
                case DescValueType.BOOLEANTYPE:    val = d.getBoolean(key); break;   
                case DescValueType.DOUBLETYPE:     val = d.getDouble(key);  break;     
                case DescValueType.INTEGERTYPE:    val = d.getInteger(key); break;   
                case DescValueType.ENUMERATEDTYPE: val = typeIDToStringID(d.getEnumerationValue(key)); break;   
                case DescValueType.UNITDOUBLE:     val = d.getUnitDoubleValue(key); break; // not quite right   
                case DescValueType.STRINGTYPE:     val = d.getString(key); break;    
              //case DescValueType.REFERENCETYPE:  val = getReference(brush.getReference(key)); break;    
                default:                           val = d.getType(key).toString();  
            }   
            if (val != undefined) {   
                var name = typeIDToStringID(key);   
                if (!name) name = typeIDToCharID(key);   
                if (typeof(val) == "string") eval("ret." + name +"="+val.toSource());  
                else eval("ret." + name +"="+val);    
            }   
        }                   
        return ret;   
    }   
    catch (e) { alert(e); }   
}   
  
function logInfo(Txt){
    try {	
       var file = new File(Folder.desktop + "/temp1.txt"); 
       file.open("w", "TEXT", "????"); 
       //alert(file.encoding);
       file.encoding = "UTF8";
       file.seek(0,2);   
       $.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';
       file.writeln(Txt); 
       if (file.error) alert(file.error);
       file.close();
       file.execute(); 
    }
    catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
};   

 

 

JJMack
Stephen Marsh
Community Expert
Community Expert
September 11, 2021

Combining all three...

 

var doc = app.activeDocument;
if (doc.colorProfileName !== "Adobe RGB (1998)" && doc.bitsPerChannel !== BitsPerChannelType.SIXTEEN && doc.mode.DocumentMode !== "RGB") {
// Do something if the active doc profile is not Adobe RGB (1998) & not 16bpc & not RGB mode
}

 

BQ5EF6Author
Participant
September 11, 2021

Thank you so much!

Stephen Marsh
Community Expert
Community Expert
September 11, 2021

For the mode:

 

if (app.activeDocument.mode.DocumentMode === 'RGB') {
    alert('RGB');
}
Stephen Marsh
Community Expert
Community Expert
September 11, 2021

Bit depth:

 

if (app.activeDocument.bitsPerChannel === BitsPerChannelType.EIGHT) {
    alert("8 bpc");
}
Stephen Marsh
Community Expert
Community Expert
September 11, 2021

For the ICC profile name, you should be using:

 

app.activeDocument.colorProfileName