Skip to main content
JtotheILL
Participating Frequently
August 11, 2018
Question

Suppress the dialog menu when running an ATN within a script

  • August 11, 2018
  • 1 reply
  • 1621 views

Is there a way to suppress the dialog menu when running an ATN file? 

I have a script that I use to process a number of files within a folder. 

Essentially it opens a file, selects all, copies the image.  Then it opens another file and pastes the copied image into the file. 

The result is a file with the proper filename and two layers (the original + the pasted image layer). 

The script then runs an action file (ATN) which activates the pasted image layer and selects the color range black(creates a selection, dotted area).  Then I change to the other layer and use the selection to cut the area that is all black.  The problem is that occasionally there is no black in an image so the selection is empty.  Which pauses the script and displays an error saying that "The command Cut is not currently available" with the options to Continue or Stop. 

If I manually hit continue the script continues running, doing its job.  However, it halts the progress until I hit Continue.  Is there a way to suppress the dialog menu when running an ATN file? 

I tried this within my script but it doesn't stop the dialog box.

app.displayDialogs = DialogModes.NO;

Here is a code snipit.  

//vb_

//Metal1

//Search folder for VIEW vb_ & Metal1 png 

var str1 = '*vb_**Metal1.png*'  ;

var fileList = fold.getFiles(str1); 

for ( var i = 0; i < fileList.length; i++ )

// Open VIEW vb_ & Metal1 png

app.open( fileList ) ;//you can enter code here to check for the file types you want or to process the images. You can get all the file here with a search mask. 

//Search folder for VIEW vb_ & M2bpng 

var str2 = '*vb_**M2B.png*'  ;

var fileList = fold.getFiles(str2);

for ( var i = 0; i < fileList.length; i++ ) 

// Open VIEW vb_ & M2B png Copy Then Close and Paste In Place in original file

app.open( fileList ) ;

//prepare active document

activeFile= app.activeDocument;

//sctiveFile.resizeImage(width,height); //resize image into given size i.e 640x480

activeFile.selection.selectAll();

activeFile.selection.copy(); //copy image into clipboard

activeFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes

//LOAD ACTION FILE

//activate function to paste in place

pasteInPlace();

createSmartObject(app.activeDocument.activeLayer);

app.displayDialogs = DialogModes.NO;

app.doAction('BlackMetal','MyTrimMetal')

//Save Trimmed Metal1

// reference open doc

var doc = app.activeDocument;

// set save options

var opts = new ExportOptionsSaveForWeb();

opts.PNG8 = false;

opts.transparency = true;

opts.interlaced = false;

opts.quality = 100;

opts.includeProfile = false;

opts.format = SaveDocumentType.PNG; // Document Type

//Overwrite file

// save png file in same folder as open doc

activeDocument.exportDocument(doc.path, ExportType.SAVEFORWEB, opts);

activeDocument.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes

    This topic has been closed for replies.

    1 reply

    JJMack
    Community Expert
    Community Expert
    August 12, 2018

    Yes a script can suppress its dialog the script need to be a Photoshop Plug-in script like Adobe's Fit Image.jsx.    A  Photoshop Plug-in script has code to support actions coded in.   When the Script is being recorded into your Action the scripts records the settings you use recording the step in its dialog into the actions step.  When the Actions is played the Action Manager passes the recorded setting to the script the plug-in script uses these settings and bypasses displaying its dialog.

    A script can not override an actions interactive step and make it none interactive.  Scripts also  often use Action Manger Script code the step you added "app.displayDialogs = DialogModes.NO;" is normally use in conjunction with the Action Manager Script code within the script.

    The script you posted parts of shows not signs of any ScriptUI dialog.  The script may be using a Photoshop step in an interactive mode or some document condition is changing a Photoshop step to be interactive.   Make sure the Action the Script is using 'BlackMetal','MyTrimMetal' does not have any interactive steps.  An Inserted menu items that would open a dialog or  steps with the step dialog turn on to make it interactive a stop message.

    Script can catch errors like you show if the error in the script it may do something about the error or ignore the error.  If the error happen in the Action the script may be able to catch it  then just close no save and move on.  I do not know you did not post the full script and a never tried to catch an action.

    JJMack
    JtotheILL
    JtotheILLAuthor
    Participating Frequently
    August 12, 2018

    The ATN file was created and runs inside my script because I couldnt figure out how to script a few of the required steps.

    The script runs perfectly 95 percent of the time.  But occasionally it finds an image that has no black pixels in it so when its told to Cut the black pixels it stops and pops up the dialog. 

    The ATN  (app.doAction('BlackMetal','MyTrimMetal') does the following...

    Selects the top layer in the layer panel.

    Goes to Select > Color Range > (Shadows - Fuzziness and Range are 0)  //This is used to select only True Black items in the image 

    Change to Layer 1 (the second layer in the list) and uses the previous selection to cut this layer

    Then selects all on Layer One and deletes

    Paste cut item

    But the problem occurs with there is no true black and the cut fails and pops up the dialog saying the cut tool is not available.

    I dont know the best way forward.  Perhaps I should try to script the steps in the ATN so that I can suppress the dialog. 

    Any thoughts?  I appreciate the help.  Thanks in advance.

    JJMack
    Community Expert
    Community Expert
    August 12, 2018

    Where do the errors occur in the Action or in the Script.    In the  Script have you tried coding a try catch  like around steps like the do action or around some of the script steps known to fail.   Have you tried catching the errors that you known happen with some of the document you process. Have you tried handling the errors?  You are getting Error dialogs try to catch the errors and handle them in the script.  Actions can not handle errors. I also do not know if  putting the do action step inside of  a try catch works I never tried I feel it may.

    ....

    try {app.doAction('BlackMetal','MyTrimMetal');}

    catch {code needed to handlke the case where the action fails}

    ...

    You can also convert your action into a script using X's xtools package  script  ActionFileToJavascript.jsx.  The code will be easer to read then Action Manager Code recorded by Adobe scriptlistener plug-in. However, the script will be action manager code.  You should  then be able to incorporate the code into your script eliminating the do action step. Everything will be contained in your script should be able to catch the errors you show happen. And also know exactly which steps fail by having each step in its own try catch. You can nest  try catch statements a catch can trough and error for and outer catch to catch or not let Photoshop show the user the error

    Also for problems like this you should  be using the Photoshop Scripting forum Photoshop Scripting I only hack at Photoshop Scripting I do not  know JavaScript or Photoshop Scripting however I can hack other's code, copy and past.   I find I can hack what I need.

    JJMack