Compare number of items in two folders then move an item if same number

Hello,


I've succesfully created a Folder Action with Automator that once an image file is dropped into a folder called "Funnel", that file will run through some Photoshop processing and then be saved in two different formats in two respective folders (let's call the two folders "A" and "B").


The problem that I'm running into is that I can't drop a bunch of files into the "Funnel" folder at once because it will bog down Photoshop. My solution to this is to create a folder called "Waiting Room" where I will dump a large amount of files. I'm trying to write a Folder Action/AppleScript that will recognize when a file (or files) have been dropped into "Waiting Room", it will then look at the number of items in folders "A" and "B" and if the numbers are the same, that means that Photoshop is done processing the last image it worked on and is free for more work. If that's the case, it will move the last item in the "Waiting Room" to "Funnel" which will then process the file. Because Photoshop will save one format to folder "A" before it saves another format to folder "B" the two folders wont have the same number of items and "Waiting Room" will not be able to transfer another file to "B" until both folders have the same number of items again. This should force it so that Photoshop is only receiving one image file at a time to process.


This is what I've done so far and it isn't working.

User uploaded file

I get the following error:

User uploaded file


Please help! I'm pretty new to all of this and am guessing at the AppleScript stuff. Thank you!!!

OS X Mountain Lion (10.8.5)

Posted on Dec 28, 2013 2:29 AM

Reply
7 replies

Dec 28, 2013 9:01 PM in response to Niel

Thank you so much Niel! I no longer get the error. The only thing is, it only processes one file and then the rest of the files just sit in the "Waiting Room" folder. I thought that writing 'return 30' would make the script check folders "A" and "B" every 30 seconds, esentially looping the script, but it isn't working. Thoughts?


Also, keep in mind that there is a short moment where the last file in "Waiting Room" has been passed to the "Funnel" folder and photoshop is doing it's thing and is about to save a version of that file in folder "A". So although Photoshop is currently busy, folders "A" and "B" still have the same quantity, so the script may want to throw a bunch of files into "Funnel" rapidly until Photoshop finally saves something in "A" and it no longer matches the quantity in "B". That's why I thought a 30 second buffer might be a good idea.


Thanks again for taking the time. Cheers!

Dec 28, 2013 9:15 PM in response to rdarton

Use the following:


repeat

tell application "Finder"

if (count items of folder "Documents:A" of home) is (count items of folder "Documents:B" of home) then

move last item of folder "Documents:Waiting Room" of home to folder "Documents:Funnel" of home

end if

end tell

delay 30

end repeat


Note that this script version will not stop looping unless an error occurs or it's manually stopped.


(96267)

Dec 28, 2013 9:36 PM in response to rdarton

To keep it from runnin infinitely, would it be possible to add something like?:


repeat until (count items of folder "Documents:Waiting Room" of home) = 0


If so, where would the line go in the script?


Becuase I'm adding this script to a Folder Action (see first picture I posted), would the script kick into gear when files are dropped in the folder, stop running when the folder is empty and then start running again once new files are dropped in the folder again?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Compare number of items in two folders then move an item if same number

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.