Skip to main content
Participant
May 3, 2019
Question

Generate batches of quotes script not working? Error 24: doc.Saveas is not a function

  • May 3, 2019
  • 3 replies
  • 603 views

My mission:

I want to create a script that will generate a batch of quotes easily with reference and source included without having to do it manually all the time. The script will keep everything in place and simply change the text, so no further styling is needed. etc.

The script will allow us to simply add text of quote, reference and source and then save as jpeg, gif or jpg,etc.

I am following a YT tutorial here except I've followed along exactly yet I still receive an error, I am thinking i'm using an old method?

Note: I am half way in the middle and won't continue until this is fixed. if you can help me achieve this script all together, that will be better!

Example:

My current code:

//change text* 10

// quote  > quote-text

// source > source-text

// reference > reference-text

var quoteGroup = app.activeDocument.layerSets.getByName('quote');

var quoteLayer = quoteGroup.layers[0];

quoteLayer.textItem.contents ='Hello World'; //textitem >text layout

// change jpeg

saveJpeg('hello-world');   //<<file name here

function saveJpeg(name) {

    var doc = app.activeDocument;

    //where to output saveJpeg

    var file = new File(doc.path + '/' + name + '.jpg');

    //save options

    var opts = new JPEGSaveOptions(); //this is ref to save JPEGSaveOptions

    opts.quality = 10;  //quality

    doc.SaveAs(file, opts, true);

}

//alert(quoteGroup.name);

error:

error 24: doc.Saveas is not a function. Line 23

->       doc.Saveas(file,opts,true);

tutorial followed:

Photoshop Scripting Tutorial - YouTube

Note: I find the photoshop scripting reference unclear and confusing for someone who has NOT gotten into JavaScript yet.

i APPRECIATE A RESPONSE! THANK YOU.

This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
May 3, 2019

error:

error 24: doc.Saveas is not a function. Line 23

->       doc.Saveas(file,opts,true);

doc.saveAs

???

Participant
May 3, 2019

Hello Stephen,

Thanks for the response. Surprisingly your suggestion did make a change, however... I am left with another issue:

Based on this error, it seems like it is attempting a save and the function worked by fixing it to saveAs and not Saveas.

What can we do about this error, it didn't even finish error message??

Stephen Marsh
Community Expert
Community Expert
May 3, 2019

It does not surprise me, JS is case sensitive, so one has to be precise and the syntax is not always consistent as one may expect.

Are you using ExtendScript Toolkit, what is the debugger message?

Has the open file been saved so that there is a backing path that can be used by the doc.path?

P.S. I am a self-taught beginner too, with no formal knowledge of JavaScript, only what I pick-up through mucking about with in these forums.

Participant
May 3, 2019

Quick clarification:

As I try other scripts and test my code, I notice that the text doesn't align and change properly as I would like (like template).

If text exceeds line limit, it doesn't resize, change font, etc.

I would like information on how to achieve that!

---

more questions as I continue to do research and working on this!

May 3, 2019