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

Repeating Script based on Hot folder content

Explorer ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

I have a script that is ran based on contents of a Hot folder I've created.. The script works flawlessly when placing one file at a time... but I'd love to be able to fix it so that I can drop multiple files in and it repeat the script on each individual file until all files have been processed. Thanks in advance for any help.

#target illustrator

var fo = Folder ( '~/Desktop/Illustrator Hot Folder/Reveal Zund Marks/IN' ); 

var files = fo.getFiles ( /* you may want to use a filter function here. See doc */ ); 

var file, newimage; 

 

file = files.pop();

app.open(file);

//Through Cut Forward

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     bringThruCutForward();

}

wrapper();

saveAsPdf( 

    '~/Desktop/Illustrator Hot Folder/Reveal Zund Marks/OUT', 

    'Proof' + activeDocument.placedItems[0].file.name, 

    "Dynagraphics PDF - Flat - Layers" 

); 

/**

* sample save the activeDocument to the pdf file

*

* @param {String} targFoldPath - any destination folder path

* @param {String} targFileName - the activeDoocument.name or any another name

* @param {String} pdfPresName - the name of existing pdf preset

* */ 

function saveAsPdf(targFoldPath, targFileName, pdfPresName) { 

  var destFolder    = new Folder(targFoldPath); 

  var pdfOpts       = new PDFSaveOptions(); 

  pdfOpts.pDFPreset = pdfPresName; 

  var targFile      = new File(destFolder + '/' + targFileName); 

  activeDocument.saveAs(targFile, pdfOpts); 

//Close the open Document Command

app.documents[0].close(SaveOptions.DONOTSAVECHANGES)

//This line is set to clear the file out of the HotFolder when complete... Works great

var myFolder = Folder('~/Desktop/Illustrator Hot Folder/Reveal Zund Marks/IN' );

var myFiles = myFolder.getFiles();

for(var i=myFiles.length - 1; i > -1;  i--){

myFiles.remove();

  };

TOPICS
Scripting

Views

1.9K

Translate

Translate

Report

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
Adobe
Valorous Hero ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

The line to clear out the file clears out all files!

change it to a simple file.remove() by using your very first 'file' variable.

Put that into line 52 and remove the ones below.

Votes

Translate

Translate

Report

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
Explorer ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

So to make sure I'm understanding you... If I replace everything I have from line 52 to the end with the file.remove() the script will cycle through until all of them are processed?

Thanks

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

No, I guess it should be really re-written so that the code is inside of a loop. The stuff after line 52 removes all the files, I guess it could be left alone and be ran right where it's at after the main loop completes. I was originally thinking your folder action could run a single-action script over all the files, if it worked that way. But if the actions are ok with multiple files dropped in (as in, it only calls the script after all the files are placed in, not one time for every placed file separately), then one loop can be used in the script.

This is a great exercise on code building, you can write down your steps and make some pseudo-code flowchart to help.

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

LATEST

Also curious about your hot folder workings. Does it automatically open illustrator, execute script(s) and then remove the file from the folder? Or is it a folder that fills up with a few documents and then you manually run a script that processes all the files in that folder?

As to your clarification question, it's lines 55-60 that are giving you trouble. You're processing one file out of the folder, then running a for loop to delete every file in the folder. So you either need to have the script process each file in the folder before you run a loop to remove each file, or you need to lose the loop and instead simply use what Silly said above and just do a simple remove on the individual file that you just finished processing.

Let's go for the latter option. When you're writing these scripts, keep an eye out for repetition/redundancy. Anything you type more than once, can typically be reused instead of retyped. in the above script, lines 3 and 4 are identical to lines 56 and 57. You've already declared variables for your hot folder and the files inside. So you don't need to do those again. You already set a variable, "file", to the file you want to remove. So you simply need to use: file.remove() as silly said above.

One thing on which i don't agree with Silly however, is removing line 52. I think that's an important part. I would simply add :

file.remove();

to line 54 and call it a day. You should be all set after that.

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

Btw, how does your hotfolder work? How does it know to run this script when a file is dropped in?

Votes

Translate

Translate

Report

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
Explorer ,
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

I'm on a Windows 7 Machine.. so I use an app called Folder Actions for Windows... Once I assign a folder to be watched, it runs a .bat file to open Illustrator and run any specific script I list.  It's pretty slick and works great...

Folder Actions for Windows (Windows) - Download

The contents of the .bat file are simple... Just go to the basic notepad app and insert the following text line. just remember to save with a .bat as the extension. In some cases you may need to go to the Folder Actions window > View Tab and uncheck the hide extenstions for known file types. This way you can remove the default. txt the program wants to add..

"C:\Program Files\Adobe\Adobe Illustrator CC 2017\Support Files\Contents\Windows\Illustrator.exe" C:\Program Files\Adobe\Adobe Illustrator CC 2017\Presets\en_US\Scripts\***Your SCRIPT HERE*****.jsx

Votes

Translate

Translate

Report

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