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

Automatically run scripts on files in a specific folder

Community Beginner ,
Feb 16, 2017 Feb 16, 2017

Hello all!

I have a series of very effective scripts that I am running against a series of photoshop files. Now the big quiestion!

Is there a program to

1) "watch" a folder, so when a file is saved in that folder.

2) It runs my script(s) on that file?

If you look at it simply-- I would like to replace the "drag and drop" method used for droplets, with the "drop in the folder" method.

No doubt this would require a separate program, to consistently check the folder for new files.

This is something that I would prefer to tackle with python, but maybe you all in the community could provide me with a more "industry accepted" solution?

Oh and Ideally I would run this on both mac and PC.... though I understand if windows makes more  sense for an operation like this.

Best,

Thomas Murphy

TOPICS
Actions and scripting
11.3K
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

Enthusiast , Feb 17, 2017 Feb 17, 2017

Hi Tomas

If you manage to have a computer just to deal with it having Bridge opened on the "hotFolder", you can use Bridge to do that.

  1. Select a folder on your network to be the "hotFolder" (you can change its name and in the code itself);
  2. On the computer that will be the listener over the hotFolder, just put this code on the Bridge "Startup Scripts" folder and reopen Bridge
  3. Using another computer, put some images in the folder "hotFolder" and check is the listener event handler reacts automatically.
...
Translate
Adobe
Community Expert ,
Feb 16, 2017 Feb 16, 2017

I do not think there is a standard "Watched Folder"  than works the same on different platforms.  If you search this forum site you will find a question similar to yours in forum for several of Adobe products.  There are also questions on how the process should work.  Thing to considered like how to handle  new files being dropped in while the process is running where output is stored are process file moved out/deleted etc from the watched folder.   Should the process be started by a drop in event or on a schedule. There many thought but no standard feature that I know of.    

JJMack
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
Community Beginner ,
Feb 16, 2017 Feb 16, 2017

Can you name a program that you have used at least for mac?

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
Community Expert ,
Feb 16, 2017 Feb 16, 2017

I chose to use Windows more things are available for windows compared to Mac and Linux.

JJMack
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
Community Beginner ,
Feb 16, 2017 Feb 16, 2017

What programs have you used for windows?

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
Community Expert ,
Feb 16, 2017 Feb 16, 2017

I don't do anything like that and if a wanted to automate something like that I thing  I would just schedule a job the would check a folder on some schedule.  If I want it done immediately I would run the process rather than use a watched folder. I would also think that Mac OSX would have a scheduler like windows.

JJMack
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
Community Beginner ,
Feb 17, 2017 Feb 17, 2017

yeah I know these programs exist. I'm asking for recommendations.

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
Enthusiast ,
Feb 17, 2017 Feb 17, 2017

Hi Tomas

If you manage to have a computer just to deal with it having Bridge opened on the "hotFolder", you can use Bridge to do that.

  1. Select a folder on your network to be the "hotFolder" (you can change its name and in the code itself);
  2. On the computer that will be the listener over the hotFolder, just put this code on the Bridge "Startup Scripts" folder and reopen Bridge
  3. Using another computer, put some images in the folder "hotFolder" and check is the listener event handler reacts automatically.
  4. You can then add your code in the lines (see line 25) or use the file as an argument to run other code you want;
  5. In the end, after the file was processed, just move it or remove it;
  6. This listener will be triggered anytime a file is added or removed or the cache is refreshed. It works only on a folder called "hotFolder";

Hope it helps,

var listenerHotFolder = function( event ) {

    // IMPORTANT: $.hiresTimer > 180000 this will make sure to trigger only once on cached folders like the hot folder, because when a file is detected it trigers twice (start building cache and finishing building cache).

    if ( event.object instanceof Document && event.type == 'loaded' && $.hiresTimer > 180000) {

        // only works if the active folder name is "hotFolder" case sensitive

        if (app.document.thumbnail.name.toLowerCase() == "hotfolder") {

            var myFiles_array = [];

            // if doesn't exist, creates a subfolder to move the active processing files

            var processingFolder = Folder(app.document.presentationPath + "\\processing");

            if (!processingFolder.exists) processingFolder.create();

            // You can change the image kind you want to deal with, or other file kind

            var items = Folder(app.document.presentationPath).getFiles( function(f) { return (f instanceof File && f.name.toLowerCase().match(/\.dng|cr2|jpe?g$/) != null);}); // JPG | CR2 | DNG

            for (var a=0 ; a < items.length ; a++) {

                var copied = File(decodeURI(items)).copy( File(File(decodeURI(items)).path + "/processing/" + File(decodeURI(items)).name ) );

                if (copied) {

                    $.writeln(File(File(decodeURI(items)).path + "/processing/" + File(decodeURI(items)).name ).fsName)

                    myFiles_array.push(File(File(decodeURI(items)).path + "/processing/" + File(decodeURI(items)).name ).fsName);

                    File(decodeURI(items)).remove();

                }

            }

            app.document.thumbnail.refresh();

            // if files were dropped on the hotFolder, and were collected, any script can be running on each file.

            if (myFiles_array.length > 0) {

                for (var a=0 ; a < myFiles_array.length ; a++) {

                    // here you can put your code

                   

                    // this is just an exemple to test (you can delete this later:

                    alert("Processing the File:\n" + File(decodeURI(myFiles_array)).name);

                   

                }

            }

        }

        //

        return {

            // FALSE + block last path repetition  »»  só repete o evento numa numa pasta (não repete em F5 ou em cache rebuild) Resumo: sá actua se navegar numa nova pasta

            // TRUE  + block last path repetition  »»  repete em várias situações: numa nova pasta, ao criar/apagar ficheiros/pastas no folder activo, ao reordenar a primeira vez (qd cria a primeira vez o file invisivel .bridgesort)

            handled:true

        }

    }

}

app.eventHandlers.push( {handler: listenerHotFolder} );

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
Community Beginner ,
Feb 17, 2017 Feb 17, 2017

Thank you Pedro- perfect!

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
Community Beginner ,
Feb 23, 2017 Feb 23, 2017

Opps. Seems like it's not working for some reason.. I need it to launch photoshop, and it seems to fail-- is there a way to run this script via photoshop-- or can you show me an example where you plop the code in? It seems when I place my script in here it fails to run or even open photoshop.

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
Enthusiast ,
Feb 23, 2017 Feb 23, 2017

Hi

The script is prepared to function with Bridge always active (bring to front).

If you are using photoshop, Bridge will loose focus and will fail.

That is why i said to send images to the network hotFolder from another computer and leave this one to have Bridge always on focus.

There is also another chance of using the 2 apps. But more complex. If you make sure some how to make Bridge "bring to front" (to focus) when you need to run this listener, it should work. You can use BridgeTalk to communicate between the 2 apps to embed the other app code.

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
Explorer ,
Aug 29, 2021 Aug 29, 2021

Hi,

I use the scripts on this post Automatically run scripts on files in a specific folder 

Pedro Cortez Marques's answer.  it works fun. But  Could anyone tell me how to return to bridge to reactive the hotfolder listner with ps scripts.

THanks a lot.

my best regards!

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
Explorer ,
Aug 29, 2021 Aug 29, 2021

Get.

BridgeTalk.bringToFront( 'bridge' )

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
Valorous Hero ,
Feb 26, 2017 Feb 26, 2017

Hi Pedro,

This script is really awesome!    I hope you wouldn't mind if I post it on my site with some sample code of my own.

Regards,
Kasyan

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
Enthusiast ,
Feb 27, 2017 Feb 27, 2017

Thank you Kasyan.

Please do.

All we need is to bring forward the hidden gems that Bridge still has.

Bridge has a lot more to give that people don't use. Specially big teams and big image data.

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
Valorous Hero ,
Feb 28, 2017 Feb 28, 2017

Thanks, Pedro!

Here is the page on my site for the future generations.

— Kas

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
LEGEND ,
Mar 03, 2022 Mar 03, 2022

Have you moved your site to another address? / ah right, you removed .com

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 ,
May 17, 2017 May 17, 2017

Thanks for the useful script. can this be modified to watch two (or more) folders at the same time?

Help will be appreciated.

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
Enthusiast ,
May 18, 2017 May 18, 2017

Hi,

I never tested to watch 2 hotFolders the same time, but I would prefer to have those 2 different folders inside an hotFolder and check them both and its contents.

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
Participant ,
Mar 02, 2022 Mar 02, 2022

Can anybody tell me if this works in CC 2022? I'm unable to get it 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
Community Expert ,
Mar 03, 2022 Mar 03, 2022
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
Participant ,
Mar 03, 2022 Mar 03, 2022
LATEST

Hi Stephen,

I will check them out this morning. Just starting my day at the office aka kitchen table.

 

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