Unless Xbytor knows something about layers that I don't I think when he said 'a hidden text layer' he meant a normal text layer with the visibility turned off. The layer would still be in the layers panel. I am not sure what you mean by 'CompsLayer'. If you mean Layer Comps, then no layer comps are not layers so don't have layer metadata. Here is an example of using reading/writing layer metadata. loadXMPLibrary(); try{ var layerXMP = new XMPMeta( activeDocument.activeLayer.xmpMetadata.rawData );// get the object }catch(e){ var layerXMP = new XMPMeta();// layer did not have metadata so create new } var lastUpdated = getLayerChangedDate();// get the date. Photoshop updates time so no need to set. setDescMetadata( 'Desc' );// set desc var comment = layerXMP.getProperty( XMPConst.NS_EXIF, "userComment" );// get comment var count = layerXMP.countArrayItems( XMPConst.NS_DC, "description" );// get the number of items if ( count == 0 ) { layerXMP.getArrayItem( XMPConst.NS_DC, "description", 1 ); } setCommMetadata('comment');// set comment lastUpdated = getLayerChangedDate();// get the date. Photoshop updates time so no need to set. alert(lastUpdated); unloadXMPLibrary(); // these function adapted from PerLayerMetdata.jsx -Copyright 2008 Adobe Systems Incorporated // to use these functions are from the Photoshop Panel Developer's Guide. function loadXMPLibrary(){ if ( !ExternalObject.AdobeXMPScript ){ try{ ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); }catch (e){ alert("Can't load XMP Script Library"); return false; } } return true; }; /** The function unloads the XMP Script Library. */ function unloadXMPLibrary(){ if( ExternalObject.AdobeXMPScript ) { try{ ExternalObject.AdobeXMPScript.unload(); ExternalObject.AdobeXMPScript = undefined; }catch (e){ alert("Can't unload XMP Script Library"); } } }; function setDescMetadata(desc){ if( app.activeDocument.activeLayer.isBackgroundLayer ){ alert( 'Can not place metadata on a background layer.'); } else { var xmp; if (desc == "") desc = " "; try{ xmp = new XMPMeta( app.activeDocument.activeLayer.xmpMetadata.rawData ); } catch( e ) { xmp = new XMPMeta(); } try{ if( xmp.countArrayItems( XMPConst.NS_DC, "description" ) == 0 ){ xmp.appendArrayItem( XMPConst.NS_DC, "description", null, XMPConst.PROP_IS_ARRAY, XMPConst.ARRAY_IS_ORDERED ); xmp.insertArrayItem( XMPConst.NS_DC, "description", 1, desc ); } else { xmp.setArrayItem( XMPConst.NS_DC, "description", 1, desc ); } } catch( e ) { alert( 'Unable to place description metadata on selected layer.\n' + e ); } app.activeDocument.activeLayer.xmpMetadata.rawData = xmp.serialize(); } }; function setCommMetadata(comm){ if( app.activeDocument.activeLayer.isBackgroundLayer){ alert( 'Can not place metadata on a background layer.' ); } else { var xmp; if ( comm == "" ) comm = " "; try{ xmp = new XMPMeta( app.activeDocument.activeLayer.xmpMetadata.rawData ); } catch( e ) { xmp = new XMPMeta(); } try{ xmp.setProperty( XMPConst.NS_EXIF, "userComment", comm ); } catch( e ) { alert( 'Unable to place metadata on selected layer.\n' + e ); } app.activeDocument.activeLayer.xmpMetadata.rawData = xmp.serialize(); } }; function getLayerChangedDate(){ var ref = new ActionReference(); ref.putProperty( charIDToTypeID( 'Prpr' ), stringIDToTypeID( "metadata" ) ); ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); var desc = executeActionGet( ref ); if ( desc.hasKey( stringIDToTypeID( "metadata" ) ) ){ desc = executeActionGet( ref ).getObjectValue( stringIDToTypeID( "metadata" ) ); var timeInSeconds = desc.getDouble( stringIDToTypeID("layerTime") ); var d = new Date(); d.setTime( timeInSeconds * 1000.0 ); return d.toLocaleString(); } };
... View more