Skip to main content
virakones
Participant
December 8, 2023
Answered

Best approach to read and export channel names? Ideally into a database of some sort.

  • December 8, 2023
  • 1 reply
  • 325 views

In this context, channel layers are used in a way where they are individually printed onto physical media and labelled with the name of the channel. 

 

To save time manually opening each file and copying the channel names, is there a way to export those names out of a .PSD file programmatically to save into either a csv or into a database?

 

What's the best approach to get the names  of a channel in a Photoshop .psd?

 

 

This topic has been closed for replies.
Correct answer Stephen Marsh

@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();

 

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
December 8, 2023

@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();

 

 

Participant
December 8, 2023

@Stephen Marsh 

This worked beautifully! Thank you so much for the suggestion, it's a great launching point for me

Stephen Marsh
Community Expert
Community Expert
December 8, 2023

You're welcome. As there was no example txt file I had to take a guess with a single column. It could just as easily be two columns, the first being the file name and the second the channel name.

 

Please mark my previous post as a correct answer if it answers your question, thanks.