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

Automatically run scripts on files in a specific folder

Community Beginner ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

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

Views

7.8K

Likes

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

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.
...

Likes

Translate

Translate
LEGEND ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

JJMack

Likes

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

Copy link to clipboard

Copied

What programs have you used for windows?

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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} );

Likes

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

Copy link to clipboard

Copied

Thank you Pedro- perfect!

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

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!

Likes

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

Copy link to clipboard

Copied

Get.

BridgeTalk.bringToFront( 'bridge' )

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

Thanks, Pedro!

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

— Kas

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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

Help will be appreciated.

Likes

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

Copy link to clipboard

Copied

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.

Likes

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

Copy link to clipboard

Copied

Can anybody tell me if this works in CC 2022? I'm unable to get it to run.

Likes

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

Copy link to clipboard

Copied

Likes

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

Copy link to clipboard

Copied

LATEST

Hi Stephen,

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

 

Thank you!

Likes

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