Copy last two images from every sub folder into one location

I am new to scripting on the mac and wanted to reach out to see if some one had a similar script that I could utilize for my scenario.

I have one folder that has hundreds of sub folders and in each sub folder there are about 20+ images. Through out the day this set of sub folders is constantly changing where folders are being created and images added and then the entire folder is deleted. What I am trying to do is have this folder be watched by a script that will take the last 3 images by modified date and copy them into another single folder. The number of images in the folder could range from 26 to 100 or more.

The other option instead of having a watched folder if I could select a range of folders would also be fine

Let me know if there is some thing that could work for me scenario.

Milkman

Model: Powerbook
AppleScript: 2.23
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

To get the last 3 modified files of a folder:

do shell script "ls -t $HOME/Desktop | head -3"

Hello!

You had various wishes, and this is late, but this copies the 3 newest files from your folder structure.

you’ll have to specify the paths as posix paths, that is the way you see them in the terminal.

First we find all folders that have been modified today, then we get the three newest files from each folder, then we sort the lot, extract the filenames from this.

Secondly we copy those files into the folder you want them in.


set posixfolder to quoted form of "/Users/you/images"
set toFolPxPath to quoted form of "/Users/you/your/image/container"
set theRes to paragraphs of (do shell script "for i in `find " & posixfolder & " -type d -mtime 0 -depth 1 ` ; do  find \"$i\" -type f -depth 1 -exec ls -tl {} \\; |head -3 ; done |sort -r -k 7M -k6 -k 8 |head -3 |tr -s \" \"|cut -f 9 -d \" \"")

repeat with aPxFile in theRes
	do shell script "cp " & quoted form of aPxFile & " " & toFolPxPath
end repeat

You have to test that it works. I have tested it, but I am not sure whether it is totally independent of system settings or not, sorting the output, that is.