Help with script to copy several thousand jps images to a folder

Hello to all

Would appreciate help on a script
Am complete newbie - have looked far and wide on the net but cant figure it out

Goal is simple

Have several folders containing 600 jpg and 600 raw photos
Want to copy the 600 jpgs to a different folder

Appreciate any help

Best
Jay

Model: MacBook Pro
AppleScript: AppleScript 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Jay:

Try this:

set source_Folder to choose folder with prompt "Choose a Source folder:"
set destination_Folder to choose folder with prompt "Choose a Destination folder:"
with timeout of weeks seconds --This will give the script plenty of time to work
	tell application "Finder" to move (every file in source_Folder whose name extension is "jpg") to destination_Folder
end timeout

--tell application "Finder" to duplicate (every file in source_Folder whose name extension is "jpg") to destination_Folder

The way it is currently written will move all the .jpg files to the destination folder. If you really want to copy them, replace the term move with the term duplicate as shown in the terminal information line.

Good luck,

Craig

Thank you so much

It works perfectly

It did in 30 seconds what would have taken me 30 minutes - for each folder - and I had 6

Best
Jay

BTW
I am amazed by the power of the scripting language
Can you recommend the best book to learn Applescript

Jay:

We have a books/resources section here: http://macscripter.net/books/

My two favorite texts are: http://macscripter.net/books/reviews/124_0_1_0_C/

and http://macscripter.net/books/reviews/63_0_1_0_C/

You will also find plenty of good beginning/intermediate/advanced articles on various topics here: http://macscripter.net/unscripted

As you can see, MacScripter.net is truly the central source for all things AppleScript.

BTW, just out of curiosity, did you use the move or the duplicate?

Craig

To answer your question I used “duplicate” and it worked just fine - Thanks again

Here’s what I wanted the script for

I took pictures from a remote camera every 5 minutes for the 5 days leading up to Boston’s July 4th Fireworks Celebration
I shot in both jpg and raw

The goal was to make a time lapse movie but that needed the JPG images and not the raw ones
I manually selected and copied 400 or so jpgs from the first day’s shots to another folder and it took me 20 -30 minutes
Your script did it in under a minute

Unbelievable

May I pick your brain for another script

Goal
Downlaod several CF cards full of images from a card reader attached to a laptop
On insertion of the CF card have the computer create and label the folder and the images with a name I choose (or have chosen previously) ie “Swan Boats #1 7/28/07”
ON completion of download the CF Card the file transfer is verified - this is crucial to make sure I dont loose the images
Then the CF card is erased - the trash is emptied - then the CF card ejected

Best
Jay

You’ve asked the right guy, Jay. Craig is an avid photographer. Welcome to the bbs! :wink:

Adam

Thanks for the welcome and for the info

Vincent Laforet - a premier photographer of our time - described a script that Apple developed for him to do something like what I requested but I could never find the details

Hope we can come up with something

Best
Jay

Jay:

I am glad all went well with the little script. I will certainly do what I can to help you with your automatic CF card thingy, but please understand that I am a fabulous veterinarian, a very good photographer, and an acceptable AppleScripter.

Is there a reason you choose not to use iPhoto? I honestly think it is the best digital image organizer out there, and that is where I do a lot of my scripting for personal use. It essentially comes all ready to do exactly what you describe, with a single button click. Although I have read reports of persons “losing images” with iPhoto, I have had no problems whatsoever, and neither have some local friends of mine that also use it regularly. I currently have a large stack of CDs and DVDs of backup images, and a library of nearly 11,000 photos on a 1TB drive. It represents 5 years of digital photography and a fair number of scanned film images (some dating back to the 1970s). It is well organized and accessable, and iPhoto never chokes on it, although maintentance tasks take some time these days.

Anyway, if iPhoto is not an option for you, no problem. Here is what I think we need to get started. One at a time, place each of your CF cards in your card reader, wait for it to be recognized, and run this script:

tell application "Finder" to set a to name of every disk whose ejectable is true

Try not to have any other disks or USB drives hooked up at the time you run this, so that the only ejectable item is the CF card.

For simplicity, it would be nice if every card had the same name, but as long as we know all the names (if they are different), it should be OK. The only way I am aware of to force the cards to have the same name is to have the camera format each card.

Let me know your thoughts and we can get this baby moving for you.

Craig

We are in similar fields - I’m a hand surgeon in Boston

I also take a lot of pics and freelance for the Globe - mainly high school sports and there all on deadline

Let me describe what I am trying to do

I shoot a game
Want to download my card to computer at end of each quarter - while it downloads I keep shooting with a new card
Want to tell the program before the game begins the name of the folders to be created ie “BostonVsCambridgeFootball7/20/07”
Want to simply put the card in the card reader and have it start the process
Program sucks in the images to a folder labelled “BostonVsCambridgeFootball7/20/07-1”
Once images are copied it verifies they really have been transferred
Once above is true it erases the card and ejects it

At the end of the next quarter I do the same thing and the program creates the next folder - “BostonVsCambridgeFootball7/20/07-2”
And on and on

A variation of the above is if I shoot raw and jpg similtaneously on the same card the program would create 2 folders for each card - 1 raw and another jpg

I know you mentioned iPhoto but I work in Photoshop to edit the images and in Photomechanic to caption them

Hope we can come up with something

Best
Jay

you may find some answers in this thread also.

http://bbs.applescript.net/viewtopic.php?pid=80839

Jay:

For your purposes, a stay-open application will probably be best. I really like using launchd, but when it launches AppleScripts, it does not allow user input, so it won’t work here.

The script below is functional in its current form, but only to download the card to the correct folder and eject the card. I don’t know how your machine reads your card names (see message #8, above) so I used “CF”. Open up the script in Script Editor after you know the name of your card, and replace the “CF” with the correct card name. Be sure you change both instances of “CF”. When that is done, you need to access Save As… and save the script as an application (in the File Format drop down menu) and be sure that the Stay Open box is checked. You can save it anywhere, but the Desktop is pretty convenient.

Before you double click the icon to run the application, be sure that NO CF cards are attached to the machine. Once it spools up, you will be prompted to enter the name of the game. As you can see by reading the script comments, you don’t need to worry about the date, just enter the game identification. The script will make the date and track the card count for you.

global folder_root_name --For you, this would be the name of the game you are shooting
global CF_count --This will count the cards as you go, so that you don't have to
global ej_Disks --list of disks for comparison
property Pict_path : (path to pictures folder as Unicode text) --Path to Pictures folder, where all the folders will be written
property CF_transfer : false --Will switch to true while disk is being copied

on run --This is what happens when you first start the application
	set CF_count to 1 --Card counter set to 1
	set folder_root_name to (text returned of (display dialog "Please enter root name of folder:" default answer "") & space & (my WriteDate(current date))) --You enter the name of the game, but DO NOT enter the date, the WriteDate handler will do it for you.
	set ej_Disks to (list disks) --Get a list of current disks
end run

on idle --This loop fires every 3 seconds
	if (list disks) ≠ ej_Disks and CF_transfer = false then --If the list of disks is not the same as startup, and CF_transfer state is false, we get sent to the DownLoadImages handler
		my DownLoadImages()
	end if
	return 3
end idle

on DownLoadImages()
	set CF_transfer to true --Switch the state to true, so that nobody will bother us whil the download is happening
	set CF_folder to folder_root_name & "-" & CF_count --Make the unique folder name
	tell application "Finder"
		make new folder at Pict_path with properties {name:CF_folder} --make the folder
		duplicate entire contents of disk "CF" to folder (Pict_path & CF_folder) --Copy all the CF card contents to the new folder
		eject disk "CF" --eject the CF card
	end tell
	set CF_count to CF_count + 1 --Set the counter up 1
	set CF_transfer to false --reset the transfer state to false in preparation for the  next CF card
end DownLoadImages

to WriteDate(dt)
	return (dt's month as number) & "/" & dt's day & "/" & (characters 3 thru 4 of (dt's year as string))
end WriteDate

As long as all your CF cards have the same name, this baby should work to copy all the images to the new folder and eject the card so you can just pull it out of the reader when you are ready. I did not do an erase yet, because I am not sure that I know how to compare the folder to the card to do the verification thing before erasure. I will think about it, but in the meantime, please test this out with a couple of cards and see what happens.

Once the game is over, you just quit the application (like any other app) and it will be all fresh and new for the next game.

You might try MD5. “Md5 takes as input a message of arbitrary length and produces as output a 128-bit “fingerprint” or message digest” of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest."

I’ve used this with success to make certain that a file moved across a network had arrived intact. Identical files should have the same MD5 result.

set tFile to quoted form of POSIX path of (choose file)
set CS to last word of (do shell script "md5 " & tFile)
-- do the duplication, then get the CS of the new file, compare to the old, then delete the old.

That’s a good one, Adam. I was Googling around last night, and there is apparently a UNIX command entitled dircmp, which is exactly what we are looking for; it compares two directories for similarities and differences, but is strangely NOT included in our dear Mac flavor of UNIX. However, I did find this workaround using diff, and my preliminary tests are pretty promising.

MD5 is very fast, and the directory of a camera chip contains no directories so comparing file by file is very quick. Also it doesn’t matter if you’ve renamed the file – MD5 compares contents, not properties.

So, going from file to file should not take an excessive amount of time? I have never done any kind of verification work with file copying, but I also have never immediately deleted anything. I typically use ditto to move an entire folder/disk/whatever, and I like it, although it does not have a built in verification utility.

Craig

Just got out o the OR

I tried your script first thin this AM - got an error message which I forgor to copy down - but it worked ie images were transferred to Picture folder

When I just tried it again this afternoon it aske me the name of root folder - I then inserted the disk - but nothing happened

Dont know why - any advice ?

Also
All CF cards are labelled EOS_DIGITAL
Can you send the folders to Desktop instead of Pictures
Could the script when first started create 3 empty folders called "root name of folder"Quarterfinals, "root name of folder"Semifinals and "root name of folder"Finals - this is my workflow to gradually eliminate photos to get the final 5-10 that I submit

Best
Jay

Mark and Adam

I forgot to thank you guys as well

Best
Jay

Hmmm. Probably something to do with my silly (list disks) thing. I think the current version (below) is a bit cleaner. It should now work, regardless of whether the CF card is plugged in at startup or not, since now it just looks for the presence of “EOS_DIGITAL” every loop.

I changed the final resting place to the Desktop, and the three magical folders will end up there as well, but I think they will have dates associated with them. If that needs to be changed, say so, it is easily done.

As you can see from some of the other messages, Adam and I have been discussing methods of verification. Let’s get this part working correctly, then move on to that, as well as integrating the first script to sort all the JPG files out as well. Just do it all at once, right? Anyway, try this next one out, and be sure to save it as a Stay Open application:

global folder_root_name --For you, this would be the name of the game you are shooting
global CF_count --This will count the cards as you go, so that you don't have to
property Pict_path : (path to desktop as Unicode text) --Path to Pictures folder, where all the folders will be written
property CF_transfer : false --Will switch to true while disk is being copied

on run --This is what happens when you first start the application
	set CF_count to 1 --Card counter set to 1
	set folder_root_name to (text returned of (display dialog "Please enter root name of folder:" default answer "") & space & (my WriteDate(current date))) --You enter the name of the game, but DO NOT enter the date, the WriteDate handler will do it for you.
	my MakeFinalFolders(folder_root_name)
end run

on idle --This loop fires every 3 seconds
	if (list disks) contains "EOS_DIGITAL" and CF_transfer = false then --If the list of disks is not the same as startup, and CF_transfer state is false, we get sent to the DownLoadImages handler
		my DownLoadImages()
	end if
	return 3
end idle

on DownLoadImages()
	set CF_transfer to true --Switch the state to true, so that nobody will bother us whil the download is happening
	set CF_folder to folder_root_name & "-" & CF_count --Make the unique folder name
	tell application "Finder"
		make new folder at Pict_path with properties {name:CF_folder} --make the folder
		duplicate entire contents of disk "EOS_DIGITAL" to folder (Pict_path & CF_folder) --Copy all the CF card contents to the new folder
		eject disk "EOS_DIGITAL" --eject the CF card
	end tell
	set CF_count to CF_count + 1 --Set the counter up 1
	set CF_transfer to false --reset the transfer state to false in preparation for the  next CF card
end DownLoadImages

to WriteDate(dt)
	return (dt's month as number) & "/" & dt's day & "/" & (characters 3 thru 4 of (dt's year as string))
end WriteDate

on MakeFinalFolders(rtnm)
	set extra_Folders to {"Quarterfinals", "Semifinals", "Finals"}
	tell application "Finder"
		repeat with an_folder in extra_Folders
			make new folder at Pict_path with properties {name:(rtnm & "-" & (contents of an_folder))} --make the extra folders
		end repeat
	end tell
end MakeFinalFolders

I just tested it and it did 600 files in 15 seconds (with the do shell script in the loop).

Craig

Just tested it and it works.

Thanks for the changes as well

Couple of minor things which I should have been able to fix but dont know enough yet
I have been reading the tutorials though

  • the Finals and Semifinals folders ended up in the “root name of folder date -1” folder
    Could all of these folders end up in the “root name of folder date” folder

– The structure of the CF card folders is

EOS_DIGITAL
DCIM
100EOS1D
All the images

Can we just transfer just the images and not DCIM and 100EOS1D

Any luck with the diff verification process

Thanks again
Jay