Ghoul Fool
Ghoul Fool

Reputation: 6949

Run last Photoshop script (again)

This seems like a trivial issue but I'm not sure Photoshop supports this type of functionality:

Is it possible to implement use last script functionality?

Upvotes: 0

Views: 115

Answers (1)

Ghoul Fool
Ghoul Fool

Reputation: 6949

Well... It's a bit klunky, but I suppose you could read in the scriptlistener in reverse order and find the first mention of a script file:

// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF

var scripts_folder = "D:\\PS_scripts";


var js = "C:\\Users\\GhoulFool\\Desktop\\ScriptingListenerJS.log";
var jsLog = read_file(js);
var lastScript = process_file(jsLog);

// use function to call scripts
callScript(lastScript)

// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL


function callScript (ascript)
{
  eval('//@include "' + ascript + '";\r');
}

function process_file(afile)
{
  var needle = ".jsx";
  var msg = "";

  // Let's do this backwards
  for (var i = afile.length-1; i>=0; i--)
  {
    var str = afile[i];

    if(str.indexOf(needle) > 0)
    {
      var regEx = str.replace(/(.+new\sFile\(\s")(.+\.jsx)(.+)/gim, "$2");

      if (regEx != null)
      {
        return regEx;
      }
    }
  }
}

function read_file(inFile)
{

    var theFile = new File(inFile);

    //read in file 
    var lines = new Array();
    var l = 0;
    var txtFile = new File(theFile);
    txtFile.open('r');
    var str = "";

    while(!txtFile.eof)
    {
      var line = txtFile.readln();
      if (line != null && line.length >0)
        {
          lines[l++] = line;
        }
    }

    txtFile.close();

  return lines;
}

Upvotes: 1

Related Questions