0

im quite a JS noob but trying to script my workflow. I modified a script to my needs, but suddenly the setting of app.-based properties doesnt work in a function anymore:

function myExport(Xquali, Xdpi, XAA, XSP, Xpath, BMcounter) {
  switch (Xquali) {
   case "Low": app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; break;
   case "Medium": app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM; break;
  case "High": app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH; break;
  case "Max": alert("?"); app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM; alert("!");}

Theres obvious nothing wrong with this snippet, but all properties i try to change cancel my script – and i dont know how to find out why. Do you guys have any idea, why i can change eg jpgexport stuff outside my function, but not in there?

3 Answers3

0

1 Check your syntax - you are missing one "}". Try this:

function myExport(Xquali, Xdpi, XAA, XSP, Xpath, BMcounter) {
   switch(Xquali){
       case "Low": app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW;              
       break;
       case "Medium": app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM; 
       break;
       case "High": app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH; 
      break;
      case "Max": alert("?"); app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM; 
      }
      alert(app.jpegExportPreferences.jpegQuality);}
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23
0

May i suggest a shorter snippet?

function myExport(Xquali) {
 if (!Xquali||!(typeof(Xquali)!=String)||!/low|medium|high|maximum/i.test(Xquali) ) return;
 app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality[Xquali.toUpperCase()];    
}

myExport("low"); //could be Low, LOW, low, loW,loW whatever
alert(app.jpegExportPreferences.jpegQuality);

FWIW

Loic
  • 2,173
  • 10
  • 13
  • Nice and slim…thanks for that. Since I'm a designer, who wants to enhance his workflow, my programming skills come from editing, try and error sample-scripts. So, if my code i derived works, im happy with that…but trying to understand what you enhanced, will help me get further…appriciate it. – Fritz Brause Dec 16 '15 at 07:23
0

let it drop, i dont know where I went wrong exactly...but as I rearranged my script, not housing my stuff in a function main(), then housing a function mywindow(), which calls a function Export(Xquali), which was trying to set the app.properties… Maybe thes properties had to be addressed somewhat different, as i moved their call deeper.