@virakones
I'm not sure if this is the "best approach", but it's "an approach"... I had all the bits required from other scripts, so it was just a case of a few copy/pastes and some refactoring. The CSV will be written to the desktop using the active Photoshop document name as a prefix:
/*
Log channel names to CSV.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/best-approach-to-read-and-export-channel-names-ideally-into-a-database-of-some-sort/td-p/14287022
*/
#target photoshop
var os = $.os.toLowerCase().indexOf("mac") >= 0 ? "mac" : "windows";
if (os === "mac") {
logFileLF = "Unix";
} else {
logFileLF = "Windows";
}
var sourceDocName = activeDocument.name.replace(/\.[^\.]+$/, '');
var logFile = new File("~/Desktop/" + sourceDocName + "_Channel Names.csv");
if (logFile.exists)
logFile.remove();
// Loop backward to reverse channel order
//for (var i = activeDocument.channels.length - 1; i >= 0; i--) {
// Loop forward
for (var i = 0; i < activeDocument.channels.length; i++) {
try {
logFile.open("a");
logFile.encoding = "UTF-8";
logFile.lineFeed = logFileLF;
// Doc name, channel name
//logFile.writeln(activeDocument.name.replace(/,/g, '-') + "," + activeDocument.channels[i].name.replace(/,/g, '-'));
// Channel name
logFile.writeln(activeDocument.channels[i].name);
logFile.close();
} catch (e) {
alert(e + ': Line ' + e.line);
}
}
logFile.execute();