Script to Import folder into iPhoto, no dupes

Hi All,

I am trying to write a script that will basically replicate the steps of going to iPhoto, Import files (from a folder with sub-folders and images.), ignore duplicates.

If I run the steps manually it works perfectly, the sub-folders appear as discrete events which is what we want to do. We just want a script so we can run it on a regular basis (say daily), to update the library with any additions to the folder which is part of a workflow on another computer.

Any help with a simple script to do same would be appreciated.

PS. I just realised a complication - the folder needs to be imported to a specific iPhoto Library, as we are running a separate library just for this folder. So the script needs to check the correct library is open and reopen if not.

OK, got my script to open selected iPhoto library done, (there are only 2 libraries and they sort alphabetically so arrow down works in this instance to always select the library i want to import into.)

--Open selected iPhoto Library
tell application "System Events"
	key down option
	
	tell application "iPhoto"
		activate
		tell application "System Events"
			
			key code 125
			key up option
			
			delay 3
			keystroke return
		end tell
	end tell
end tell

Ok, I added some code that I felt might import the images in a folder named “X100” - but nothing seems to happen when I run the script!

 tell application "System Events"
	key down option
	
	tell application "iPhoto"
		activate
		tell application "System Events"
			
			key code 125
			key up option
			
			delay 3
			keystroke return
			delay 5
			tell application "iPhoto"
				import from "Macintosh HD:Users:bigmac:Pictures:X100:"
				
				delay 10
				
			end tell
		end tell
	end tell
end tell

I should probably explain that the structure of the folders in finder is such that there is an “Artwork Fullsize” folder that has subfolders with each Artist’s name as a sub-folder and the actual images are in the artist name sub-folders.

When I manually tell iPhoto to import the “Artwork Fullsize” folder it does exactly what I want and imports all the images using the Artist Name sub-folders as Event names in iPhoto.

If I try to re-import it asks me if I want to import duplicates, obviously I dont and so select the option not to import duplicates and it then adds any changes from the previous import. The intent of the script is to run this routinely to update the library with the additions from the other workflow to the Artwork Fullsize folder.

(The “X100” folder is another folder on another machine that I am testing the script with)

Ok, I have managed to get the script to do what I want, the only remaining element is the “no duplications” command, can anyone help with that?

tell application "System Events"
	key down option
	
	tell application "iPhoto"
		activate
		tell application "System Events"
			
			key code 125
			key up option
			
			delay 3
			keystroke return
			delay 5
			tell application "iPhoto"
				import from alias "Macintosh HD:Users:bigmac:Pictures:X100:"
				repeat while importing
					delay 1
				end repeat
			end tell
		end tell
	end tell
end tell

OK, I seem to have managed to create a script that works, not sure it couldnt be better scripted but at least it does the job!

--Quit iPhoto if open, re-open with selected library
tell application "iPhoto"
	quit
	delay 10
	tell application "System Events"
		key down option
		
		tell application "iPhoto"
			activate
			tell application "System Events"
				
				key code 125
				key up option
--Imports images, without dupes
				delay 3
				keystroke return
				delay 5
				tell application "iPhoto"
					import from alias "Macintosh HD:Users:bigmac:Pictures:X100:"
					
					delay 3
					
					tell application "System Events"
						key code 49
						key code 48
						key code 48
						key code 49
						
						
					end tell
				end tell
			end tell
		end tell
	end tell
end tell