title: Using extendscript (javascript) how can I get the color values from the Photoshop color table
body: <p>I'm writing a Photoshop script in extendscript/javascript and I'm trying to verify that the document is using just one color (plus transparency).  What I would like to do is change the document mode to Indexed Color and then get the values in the color table.</p>
  
  <p>I have successfully changed the document mode to Indexed Color but can't figure out how to access the color table or the color values inside of it.</p>
  
  <p>My working alternative is to use a colorSampler to compare the values of each pixel, but that can take a couple of minutes to run on larger documents and speed is an issue for this project.</p>
  
  <p>Please let me know if there is a way to access the color table or if you see a way to reduce the time it takes to run this function.</p>
  
  <pre><code>function sample_color(doc, sample_rate) {
      var status = 'PASS'
      var color_sampler = doc.colorSamplers.add([0,0])
      var color_val = false  //first (and hopefully only) color value in the document
      var broke = false
      for (x=1; x &lt; doc.width; x+=sample_rate){
          if (broke){
              break
          }
          for (y=1; y &lt; doc.height; y+=sample_rate){
              color_sampler.move([UnitValue(x, 'px'), UnitValue(y, 'px')])
              try{
                  var color = color_sampler.color  //color of the current pixel
              } catch(e) {
                  var color = false  //color_sampler.color fails if the pixel is transparent
              }
              if (color != false){
                  if (color_val != false){
                      if (!color.isEqual(color_val)){
                          status = 'FAIL'
                          broke = true
                          break
                      }
                  } else {
                      color_val = color
                  }
              }
          }
      }
      color_sampler.remove()
      return status
  }
  </code></pre>