    var lut = -1;
    var lutdir = getDirectory("startup")+"luts"+File.separator;
    var list;
    var color = 0;
    var colors = newArray("Red", "Green", "Blue", "Cyan", "Magenta", "Yellow");

    var luts = getLutMenu();
    var lCmds = newMenu("LUT Menu Tool", luts);
    macro "LUT Menu Tool - C037T0b11LT6b09UTcb09T" {
         cmd = getArgument();
  	  if (cmd!="-") run(cmd);
    }
    function getLutMenu() {
        list = getLutList();
        menu = newArray(16+list.length);
        menu[0] = "Invert LUT"; menu[1] = "Apply LUT"; menu[2] = "-";
        menu[3] = "Fire"; menu[4] = "Grays"; menu[5] = "Ice";
        menu[6] = "Spectrum"; menu[7] = "3-3-2 RGB"; menu[8] = "Red";
        menu[9] = "Green"; menu[10] = "Blue"; menu[11] = "Cyan";
        menu[12] = "Magenta"; menu[13] = "Yellow"; menu[14] = "Red/Green";
        menu[15] = "-";
        for (i=0; i<list.length; i++)
             menu[i+16] = list[i];
        return menu;
    }
    function getLutList() {
        lutdir = getDirectory("startup")+"luts"+File.separator;
        list = newArray("No LUTs in /ImageJ/luts");
        if (!File.exists(lutdir))
             return list;
        rawlist = getFileList(lutdir);
        if (rawlist.length==0)
             return list;
        count = 0;
        for (i=0; i< rawlist.length; i++)
            if (endsWith(rawlist[i], ".lut")) count++;
        if (count==0)
            return list;
        list = newArray(count);
        index = 0;
        for (i=0; i< rawlist.length; i++) {
            if (endsWith(rawlist[i], ".lut"))
                list[index++] = substring(rawlist[i], 0, lengthOf(rawlist[i])-4);
        }
        return list;
  }

   macro "Grayscale LUT Action Tool - C111F123dC444F423dC888F723dCbbbFa23dCeeeFd23d" {
        run("Grays");
        if (getWidth==256 && getHeight==32)
            rename("Grayscale");
   }

    macro "Edit LUT Action Tool - C005F1155C40cF6155Ca0bFa155Cc05F1655Cf40F6655Cf80Fa655Cfb0F1a55Cff1F6a55CffeFaa55" {
        run("Edit LUT...");
   }

    macro "Adjust Brightness and Contrast Action Tool - C037D04D05D06D07D08D09D0aD0bD0cD14D18D1cD24D28D2cD34D38D3cD45D46D47D49D4aD4bD6bD6cD76D77D78D79D7aD84D85Da6Da7Da8Da9DaaDb5DbbDc4DccDd4DdcDe5DebDf6Dfa" {
        run("Brightness/Contrast...");
   }

    macro "Previous LUT Action Tool - C037T4d14<" {
        cycleLUTs(-1);
   }

    macro "Next LUT Action Tool - C037T4d14>" {
        cycleLUTs(1);
   }

    macro "Invert LUT Action Tool - C037R12ccL12cc" {
        run("Invert LUT");
   }

  // Based on the LUTFileTool by Gabriel Landini
  function cycleLUTs(inc) {
       if (lut==-1)
           createLutList();
       if (nImages==0) {
          call("ij.gui.ImageWindow.centerNextImage");
          newImage("LUT", "8-bit ramp", 256, 32, 1);
       }
       if (bitDepth==24)
           exit("RGB images do not have LUTs");
       if (isKeyDown("alt"))
           lut = 0;
       else
          lut += inc;
      if (lut<0) lut = list.length-1;
      if (lut>list.length-1) lut = 0;
      name = list[lut];
      run("LUT... ", "open=["+lutdir+name+"]");
      name = substring(name, 0, lengthOf(name)-4);
      if (getWidth==256 && getHeight==32)
            rename(name);
      showStatus((lut+1) + ". " + name);
  }

  function createLutList() {
      err = "No LUTs in the '/ImageJ/luts' folder";
      if (!File.exists(lutdir))
           exit(err);
      rawlist = getFileList(lutdir);
      if (rawlist.length==0)
          exit(err);
      count = 0;
      for (i=0; i< rawlist.length; i++) {
          if (endsWith(rawlist[i], ".lut")) count++;
      }
      if (count==0)
          exit(err);
      list = newArray(count);
      index = 0;
      for (i=0; i< rawlist.length; i++) {
          if (endsWith(rawlist[i], ".lut"))
              list[index++] = rawlist[i];
      }
  }

  macro "Generate Icon String" {
      colors = 9;
      getLut(reds, greens, blues);
      str = "";
      for (i=0; i<colors; i++) {
          index = i*256/colors+ 128/colors;
          r = reds[index];
          g = greens[index];
          b = blues[index];
          str = str + "C"+toHex(r/16)+toHex(g/16)+toHex(b/16)+"F"+toHex(i*3+1)+"23d";
      }
      print(str);
  }
