Skip to content

Instantly share code, notes, and snippets.

@sttk3
Last active April 22, 2024 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sttk3/b77ade3a914c5f38c0baadd4194cafb8 to your computer and use it in GitHub Desktop.
Save sttk3/b77ade3a914c5f38c0baadd4194cafb8 to your computer and use it in GitHub Desktop.
ExtendScript: Display ICC profile name of the selected linked image in dialog by Illustrator
/**
* @file Display ICC profile name of the selected linked image in dialog by Illustrator
* [Getting Placed Image's ICC Profile with Illustrator ExtendScript](https://community.adobe.com/t5/illustrator-discussions/getting-placed-image-s-icc-profile-with-illustrator-extendscript/td-p/14569584)
* @version 1.0.0
* @author sttk3.com
* @copyright © 2024 sttk3.com
*/
(function() {
if(app.documents.length <= 0) {return ;}
var doc = app.documents[0] ;
var sel = doc.selection ;
if(sel.length <= 0) {return ;}
if(sel[0].constructor.name != 'PlacedItem') {return ;}
var imageFile = sel[0].file ;
try {
loadXMPLibrary() ;
var icc = getPropertyOfXMP(imageFile, 'http://ns.adobe.com/photoshop/1.0/', 'ICCProfile') ;
alert(icc) ;
} catch(e) {
return ;
} finally {
unloadXMPLibrary() ;
}
})() ;
/**
* load xmp library
* @return {boolean}
*/
function loadXMPLibrary() {
if(!ExternalObject.AdobeXMPScript) {
try {
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript') ;
} catch(e) {
alert('Unable to load the AdobeXMPScript library.') ;
return false ;
}
}
return true ;
}
/**
* unload xmp library
*/
function unloadXMPLibrary() {
if(ExternalObject.AdobeXMPScript) {
try {
ExternalObject.AdobeXMPScript.unload() ;
ExternalObject.AdobeXMPScript = undefined ;
} catch(e) {
alert('Unable to unload the AdobeXMPScript library.') ;
}
}
}
/**
* get xmp property value of target file
* @param {File} targetFile target File object
* @param {string} nameSpace e.g. 'http://purl.org/dc/elements/1.1/' (NS_DC)
* @return {string|undefined}
*/
function getPropertyOfXMP(targetFile, nameSpace, propName) {
var res ;
if(!targetFile) {return res ;}
try {
var xmpFile = new XMPFile(targetFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ) ;
var xmpPackets = xmpFile.getXMP() ;
if(!xmpPackets) {return res ;}
var xmpMetaObj = new XMPMeta(xmpPackets.serialize()) ;
if(xmpMetaObj.doesPropertyExist(nameSpace, propName)) {
res = xmpMetaObj.getProperty(nameSpace, propName).toString() ;
}
} finally {
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY) ;
}
return res ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment