Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Looking for script to change "save as" actions..

New Here ,
Oct 07, 2009 Oct 07, 2009

I've been working on a way to avoid having to re-record 400+ save as actions.  The nutshell is that I'm saving game art from a master file.  The master file has elements common to other pieces.  So the actions turn on the appropriate layers, save then turn off those layers and repeat the process for all 400+ pieces.   This way when changes effect all pieces it's a simple operation to resave.  Creating 400 separate files seemed like an even more cumbersome way to go and having all the art in one file made more sense.

The problem I'm running into is that I've had to change hard drives often and it means the "save as" locations of the actions are no longer available.

I've tried every way I could think of to create a workaround but there's no answer that I've found so far.  Batch processing won't work because all of the 400 pieces come from one file.  I'm hoping that scripting will allow me to at least process the "record again" actions automatically.  I want to put in the new location the "save as" actions should point to and hit "OK" and have all new "save as" actions saved.

Any thoughts?  Possibly scripts available that do this very thing?  Am I wasting my time by trying to get scripting to do this and should just bite the bullet and spend 3 or 4 hours re-recording the save as actions every time I want to save the art to a new location?

TOPICS
Actions and scripting
8.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Oct 09, 2009 Oct 09, 2009

But to answer your main question. Yes the script needs both the highlighted functions and the load symbols at the bottom in order to run.

Translate
Adobe
Guru ,
Oct 09, 2009 Oct 09, 2009

But to answer your main question. Yes the script needs both the highlighted functions and the load symbols at the bottom in order to run.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

Ok thanks for that.

Sorry to pepper you guys with questions.  I've got lots.  Trying to control myself and make a logical order out of them.   The help you both are giving is awesome!  Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

Look for a function called JSWriter.massageName(). Add this line of code just before the 'return' statement. It should fix your problem.

  n = n.replace(/^(\d)/g, '_$1');  // add '_' prefix to names begining with a number

Xbytor2, I gave this a try and no joy.  Perhaps I placed it in the wrong location?  See attached screen of the ActionFileToJavascript alteration I'd made.  The return statement I placed it before was the only one I could find immediately before the JSWriter.massageName() function within that section.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 09, 2009 Oct 09, 2009

JSWriter.massageName = function(name) {
  var n = localize(name);
  n = n.replace(/\s+/g, '');  // remove any embedded spaces
  n = n.replace(/\W/g, '_');  // replace any non-word characters with '_'
  n = n.replace(/[_]+$/, ''); // remove any trailing '_'
  n = n.replace(/^(\d)/g, '_$1');  // add '_' prefix to names begining with a number
  return n;
};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

Awesome.  Thanks.

*EDIT*

Hmmm, that didn't work either.  Still producing script with "function 000", "function 001", "function 002", etc.  No underscore.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 09, 2009 Oct 09, 2009

You're version of the code does not look like my version of the code. Here's what I have.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

Ah ok thanks for that.  When downloading files from SourceForge I'd d/l the file that had the highest version number and most recent date.  Must've misunderstood the naming convention used. 

I ran it and it worked perfectly the first time out and added the underscore before each serial. 

I probably should redo my converted actions again using the new ActionFiletoJavascript-1_4.jsx.  I'd tried running my fixed script that I'd made from the ActionFiletoJavascript found in xtools 1_6.zip and it won't work in Photoshop.  Doesn't produce any errors in ESTK though so I'm not sure.

BTW I tried running my new script from the Documents:Adobe Scripts folder.  Is that the proper location? 

Is there a specific way scripts need to be loaded to work properly?

Thanks for the one-on-one help!  Awesome that you guys are available and willing to do this.  Very cool.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

Ok I've re-converted the actions to javascript and re-did the fixing of the save actions so the proper locations are indicated.

I ran the script within ESTK and it said "No Errors" when ESTK Photoshop CS4 is selected then when Photoshop CS4 is selected "Execution Finished Result: sTID()"

I opened my file that has the proper layers in it.

I placed the script within Documents:Adobe Scripts, restart Photoshop and run the script from within Photoshop.  Nothing happens.

I created an action then ran the script then played the action.  Nothing happens.

I double-clicked the script from within Mac Finder and it goes to PhotoshopCS4 but nothing happens.

I should probably note that I've not added any lines that indicate this script should be performed on the open file.  I simply took the script from the converted acitons, made my changes and ran it.

Any ideas on what I should do next?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 09, 2009 Oct 09, 2009
I ran the script within ESTK and it said "No Errors" when ESTK Photoshop CS4 is selected then when Photoshop CS4 is selected "Execution Finished Result: sTID()"

This happens because you need to specify Photoshop as the target app. Do that either in the ESTK API or add

#target photoshop

as the first line in the script.

Any ideas on what I should do next?

Did you save the actions to separate files or to a single file? If it's an action-per-file, the action will execute when the script is run. If all actions are in one file, you need to manually call the action (or actions) that you want to run.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

Ok as I was guessing.  It occured to me that it was running but wasn't applying it to anything because the converted script had not yet been told to do so.

I tried adding the line you suggested but it still returns the same response.  Execution Finished.  Response: sTID.  I'll go back to the intro to scripting PDF as this seems like it's within my grasp to figure out on my own.  Perhaps it's not as simple as I'm guessing?

Did you save the actions to separate files or to a single file? If it's an action-per-file, the action will execute when the script is run. If all actions are in one file, you need to manually call the action (or actions) that you want to run.

I exported a set of actions to one script.  So it sounds like I need to set up some sort of instruction/command at the beginning that tells the script to run all functions listed?

All this is right on the tip of my tongue but I'd need to go back and find the particular reference to be sure I'm doing it right.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 09, 2009 Oct 09, 2009

It sounds like you need to add the line

_000();

to the bottom of your script. If that doesn't work you may want to post the full script either inline or as a zip file attachment.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2009 Oct 09, 2009

  That is awesome that you can do that with the crappy little bit of info I'm giving.  That worked perfectly.  Because the 13,000+ lines of code is choking my computer I copied and pasted the first action into a separate script and ran it from within ESTK and when photoshop opened I selected my file and re-ran it and it save the file in the proper location with the correct layers turned on.

So now I'm guessing I need to go back and add _NNN();  where NNN= is the function name, to the end of each separate section of script.  Should be easy enough to try out.

Thanks!

*EDIT*  Yep that's working.  For each section that I add that final line the output files grow by one.  Thanks guys!

Ok the last question.  Can I ask why adding that line makes it work?  I guess if it was simplified script like Michael was suggesting it would be easier for me to follow.  Right now it appears you have to keep a dozen or so variables memorized in your head to follow along.

Here's the full script for one action.  I've removed certain bits of info since they'd give away the project name and I'm under NDA.

#target Photoshop

//

// Generated Fri Oct 09 2009 15:21:23 GMT-0400

//

app.documents[0]

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

//

// Action Set title

//

//

//==================== 000 ==============

//

function _000() {

  // Show

  function step1(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "USA bkgnd");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(cTID('Shw '), desc1, dialogMode);

  };

  // Show

  function step2(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "infantry");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(sTID('show'), desc1, dialogMode);

  };

  // Show

  function step3(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "Ptn HQ");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(sTID('show'), desc1, dialogMode);

  };

  // Show

  function step4(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "5 soldier");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(sTID('show'), desc1, dialogMode);

  };

  // Save

  function step5(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var desc2 = new ActionDescriptor();

    desc2.putInteger(cTID('BtDp'), 16);

    desc2.putInteger(cTID('Cmpr'), 0);

    desc1.putObject(cTID('As  '), cTID('TrgF'), desc2);

    desc1.putPath(cTID('In  '), new File("HD location"));

    desc1.putBoolean(cTID('Cpy '), true);

    executeAction(cTID('save'), desc1, dialogMode);

  };

  // Hide

  function step6(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "5 soldier");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(cTID('Hd  '), desc1, dialogMode);

  };

  // Hide

  function step7(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "Ptn HQ");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(sTID('hide'), desc1, dialogMode);

  };

  // Hide

  function step8(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "infantry");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(sTID('hide'), desc1, dialogMode);

  };

  // Hide

  function step9(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var list1 = new ActionList();

    var ref1 = new ActionReference();

    ref1.putName(cTID('Lyr '), "USA bkgnd");

    list1.putReference(ref1);

    desc1.putList(cTID('null'), list1);

    executeAction(sTID('hide'), desc1, dialogMode);

  };

  step1();      // Show

  step2();      // Show

  step3();      // Show

  step4();      // Show

  step5();      // Save

  step6();      // Hide

  step7();      // Hide

  step8();      // Hide

  step9();      // Hide

};

_000();

//

And this repeats 94 more times for each game piece.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Oct 10, 2009 Oct 10, 2009
Can I ask why adding that line makes it work?

Take this function for example:

function helloWorld(){

     alert( "Hello World" 😞

}

The code above defines the function but if you run it nothing happens because that is all it does - defines a block of code that can be reference by name.

By adding helloWorld(); to the script that runs that block of code and the alert will appear.

And of course this is a simple example. Function can also have arguments and return objects.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2009 Oct 10, 2009

Take this function for example:

function helloWorld(){

     alert( "Hello World" 😞

}

The code above defines the function but if you run it nothing happens because that is all it does - defines a block of code that can be reference by name.

By adding helloWorld(); to the script that runs that block of code and the alert will appear.

And of course this is a simple example. Function can also have arguments and return objects.

Ok that part I recall from website javascript.  I didn't realize there were any parallels between the two.  In my brain I'm trying to keep them separate so I don't make any assumptions. 

I'm guessing though that in the most general sense the javascript language is the same as that used for website programming but what the scripting is being used to control is different?  In the case of websites it's being used to control IE, FireFox or Safari and in our case it's being used to control Photoshop or other Adobe products.  So there may be different ways it can be applied in either instance but the language is still the same?  Or are there subtle differences that are specific to the program it's being used to control?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines