What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Reply to thread

Hi Ian, it's a long time since I tried anything like this. The structure of the PSD will have changed since I wrote this script but it might give you a start.

It hopefully gives the layer names. You will have to find where the ID's are kept and add it to the script. As it is direct access to the file any App that uses jsx should work? (Just remove the UI section etc.)

[code]

#target photoshop;

function main() {

file = File.openDialog("Please select PSD file.","PSD File:*.psd");

  if(!file.exists) return;

  file.open("r");

  file.encoding = 'BINARY';

  var dat = file.read();

  file.close();

 

  var result;

  var pos =[];

  var Text= [];


  var rex = /8BIMluni/g;

 

  while ((result = rex.exec(dat)) != null) { // Find ALL occurencies of search string

  //   $.writeln(result.index+(result[0].length));

    //$.writeln(result.index); //Index of regex found

    //  alert(result[0].length); //Length of string found

    pos.push(result.index+(result[0].length));

  }

 

  function readByte(str, ofs) {

    return str.charCodeAt(ofs);

  }

  function readInt16(str, ofs) {

    return (readByte(str, ofs) << 8) + readByte(str, ofs+1);

  }

  function readWord(str, ofs) {

    return (readInt16(str, ofs) << 16) + readInt16(str, ofs+2);

  }

  function readUnicodeChar(str, ofs) {

    return String.fromCharCode(readInt16(str,  ofs));

  }

 

  for (var i = 0; i < pos.length; i++) { //loop through all finds

    var ofs = pos[i]; //offset of find

    var textLength = readWord(dat, (ofs+ 4));  //Read length of string at offset

    //alert(textLength);

    ofs += 8; //increment offset to suit

    var str = ''; //reset string to ''

 

    for (var j = 0; j < textLength; j++) { //loop through string

      str += readUnicodeChar(dat, ofs); // add char

      ofs += 2; //increment two bytes

    }

if(!str.match(/<\/Layer group/)){

    Text.push(str); //Layer name found and stored

    }

  }

var w = new Window('dialog',decodeURI(file.name));

w.lb1 = w.add('listbox',undefined,'Names');

w.lb1.preferredSize= [500,200];

w.bu1 = w.add('button',undefined, 'Exit');

w.bu1.preferredSize = [500,35];

w.bu1.onClick=function(){

    w.close(0);

    }

Text.reverse();

for (var i=0,len=Text.length;i<len;i++) {

    w.lb1.add('item',  Text[i]);

};


w.show();

};

 

main();


[/code]


What is our favorite program/app? (Hint - it begins and ends with the letter P)
Back
Top