Skip to main content
Participant
June 18, 2010
Question

Retreiving the content created with the Note Tool via Javascript??

  • June 18, 2010
  • 2 replies
  • 2046 views

Hey guys, is it possible to retrieve the text content created with the Note Tool from the tool palette  in a photoshop document via Javascript? Basically, I wanted to store some text inside the Photoshop psd document, and then later on I can use scripting to access the content to be use as variables.

I have search the Javascript scripting reference pdf and the forum here, and I can't find any info the Note Tool. Much appreciated.

This topic has been closed for replies.

2 replies

artsauce1Author
Participant
June 30, 2010

Ok, so I am using the activeDocument.info.keywords property to store my text content. The content is basically a chunk of text that contains some parameters that the user can modify to save out a document. In my script, I am using a variable to store the content from the info.keywords property. But my next hurdle is how can I extract specific part of that variable into other variables, like storing the C:\projects\Textures\ into another variable? I've done some research and got a sense that the "match" method in javascript along with the use of regular expressions might do the job. But I am stuck. Any suggestions?

info.keywords property has the follow chunk of text:

// file path to save 
path(
C:\projects\Textures\)  
// save file format (psd or tga, etc)
format (tga
// include a single alpha channel with the file y/n 
alpha(n
// alpha name - default should be "alpha1" 
alphaName(alpha1
// scale from the original size 
scale(.5
//sharpening
sharpen(.5)

script code:

var saveDoc = activeDocument.info.keywords;

var savePath = saveDoc[0].match(regular expression goes here); // how to grab C:\projects\Textures\ from the saveDoc variable???
alert(savePath);

Inspiring
June 30, 2010

Use either json to store the info as a serialized JS object, or use something simpler like the .ini file format.

json has the advantage that you just have to eval the string to get the object. .ini format has the advantage that it's human readable/editable.

Here's a function I use for convertion .ini strings into simple objects:

function iniFromString(str, ini) {
  var lines = str.split(/\r|\n/);
  var rexp = new RegExp(/([^:]+):(.*)$/);

  if (!ini) {
    ini = {};
  }

  for (var i = 0; i < lines.length; i++) {
    var line = lines.trim();

    // skip empty lines. lines that begin with '#' are comment lines
    if (!line || line.charAt(0) == '#') {
      continue;
    }
    var ar = rexp.exec(line);
    if (!ar) {
      alert("Bad line in config: \"" + line + "\"");
      continue;
      //return undefined;
    }
    ini[ar[1].trim()] = ar[2].trim();
  }

  return ini;
};

schroef
Inspiring
August 25, 2017

DOes anyone know if in the newer Photoshop its possible to access or add data for the Note tool?    

Inspiring
June 19, 2010

There is no direct access to notes/annotations.

But you could store your text in the document's metadata.

artsauce1Author
Participant
June 23, 2010

Thanks, so when you mention "document's metadata", are you refering to the Document.info property?

Inspiring
June 24, 2010

Yes and if you have a version of Photoshop( CS3 or better ) that supports AdobeXMPScript you can access all the metadata including setting your own custom namespace.