Multiple problems copying images

Hi,
I’m as new as they come in this applescript business, and I’m not getting anywhere with my script.
This is what I want to do (phase 1):
copy all jpeg files in the DCIM folder and in all its subfolders (the subfolder names change) (on the eos_digital removable drive) to a single folder named import in my home dir.
copy all RAW files (.crw) in the DCIM folder and in all its subfolders (the subfolder names change) (on the eos_digital removable drive) to a new folder named with today’s date in the RAW folder in the pictures folder in my home dir.
eject the removable drive eos_digital


(Phase 2) I havent even begun to try this part.
start iPhoto,
have iPhoto import all files in the import folder in my home dir.
(note. I want to choose all the files, not the folder itself to be imported, in order to have iPhoto name this import session “Roll xxx”, instead of naming it “import” (the name of the folder))
when done importing, delete all files from the import directory.

Ok, I basically have nothing so far,
I know how to reference a folder, get a list of items in a folder, I think I’m supposed to use the duplicate command, but i dont know how to put this stuff together.
Any help great or small, will be very well appreciated! :slight_smile:

Phase 1:

copy all jpeg files in the DCIM folder and in all its subfolders (the subfolder names change) (on the eos_digital removable drive) to a single folder named import in my home dir.

set jpeg_import_folder to (path to home folder as string) & "import"
set raw_import_folder to (path to pictures folder as string) & date string of (current date)
set DCIM_folder to "eos_digital:" -- I don't know where this is, so adjust as necessary

tell application "Finder"
	-- first check the folders exist
	if not (exists folder jpeg_import_folder) then
		make new folder at (path to home folder) with properties {name:import}
	end if
	if not (exists folder raw_import_folder) then
		make new folder at (path to pictures folder) with properties {name:date string of (current date)}
	end if
	duplicate (every file in entire contents of folder DCIM_folder whose name ends with "jpg") to folder jpeg_import_folder
	duplicate (every file in entire contents of folder DCIM_folder whose name ends with "crw") to folder raw_import_folder
	eject disk "eos_digital"
end tell

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Phase 2:

have iPhoto import all files in the import folder in my home dir.

On the import session name, I recommend something different from what you asked for. You say you want to choose all files, but I think it would be better to have iPhoto ask you for the name for the import, then import all files into it. ‘choose file’ can get very unwieldy when trying to select a large number of files.

That said, I can’t seem to find the right syntax for importing an arbitrary file on disk. I’ll keep playing until/unless someone else comes up with an answer.

ok that is a nice script, thank you! :smiley:

this is what I have been puting together since last night,
note that the the folders and the extensions do not reflect the final folder placement,
I made these folders on the desktop just while I was trying and checking the script.
I also discovered that the subfolders I need to copy from are always named "number+canon
but in your code it is not even relevant,
does “in entire contents of folder” include files in subfolders?
also, my comments in the script may be a bit unorthodox since I’m not expericenced with scripting

tell application "Finder"
	--set the folder
	set dcfol to folder "dcim" of folder "eos_digital" of folder "desktop" of folder "kristjan" of folder "users"
end tell

--set the canon folders to the list canonfolders
set canonfolder to every item in dcfol whose name ends with "canon"

--count the number of canon folders (to use with repeat)
set canoncount to length of canonfolder

--make a counter
set counter to 0

--repeat the following block the number of times there are canon folders
repeat while (counter < canoncount)
	--increases the counter, to reflect both the folder to copy from and to indicate where we are in the repeating process
	set counter to counter + 1
	--uses the counter to choose the working directory of copying
	set workfolder to item counter of canonfolder
	--chooses only jpeg files in this folder
	set onlyjpegs to every file in workfolder whose name ends with ".rtf"
	--copies the list of jpegs to the import folder
	tell application "Finder" to duplicate onlyjpegs to folder "output" of folder "desktop" of folder "kristjan" of folder "users" with replacing
	--check the counter to see wheter to repeat or end
	log counter
end repeat

again thank you very much!!

ok, here’s the complete working script,
I think I may adjust some little things, like the raw folder names are unnecessarily long, maybe eliminate the “last import” folder etc.
but I am very pleased that with my first applescript project I have completed the objective.
Thanks to Camelot for designing the copying part, and Apple for the best part of the UI script for the import to iPhoto process, and to me for connecting it together and designing the file moving block all by myself :smiley:

here’s the complete code:

set jpeg_import_folder to (path to home folder as string) & "Import"
set raw_import_folder to ("Macintosh HD:Users:kristjan:Pictures:Raw import:") & date string of (current date)
set DCIM_folder to "EOS_DIGITAL:DCIM:"

tell application "Finder"
	-- first check the folders exist 
	if not (exists folder jpeg_import_folder) then
		make new folder at (path to home folder) with properties {name:"Import"}
	end if
	if not (exists folder raw_import_folder) then
		make new folder at (folder "raw import" of folder "pictures" of folder "kristjan" of folder "users") with properties {name:date string of (current date)}
	end if
	--this block move files from last import to the trash, and files from import to last import    
	set import_folder to (path to home folder as string) & "import"
	set last_import to (path to home folder as string) & "last import"
	set trash_folder to (path to trash folder as string)
	set trash_list to every file in folder last_import
	set move_list to every file in folder import_folder
	move trash_list to trash_folder
	move move_list to last_import
	--copies the files from the card to appropriate folders
	duplicate (every file in entire contents of folder DCIM_folder whose name ends with "jpg") to folder jpeg_import_folder with replacing
	
	duplicate (every file in entire contents of folder DCIM_folder whose name ends with "crw") to folder raw_import_folder with replacing
	--ejects teh photo card
	(*eject disk "eos_digital"*)
end tell

--imports files from the import folder to iPhoto
set import_folder to "Macintosh HD:Users:kristjan:Import:"
set import_path to the POSIX path of import_folder

tell application "iPhoto" to activate
delay 1
tell application "System Events"
	tell process "iPhoto"
		keystroke "I" using {command down, shift down}
		keystroke "/" using control down
		delay 1
		tell window "Import Photos"
			tell sheet 1
				set value of text field 1 to import_path
				keystroke "A" using {command down}
				click button 1
			end tell
			click button 1
		end tell
	end tell
end tell