Scripting Image Capture for downloaded photos

I’ve been trying my damndest to create a simple script that Image Capture will execute as an automatic action after downloading pics from my camera. So far, I can’t even get this one to work:

set this_item to "Users:username:Pictures:FromCamera:"
-- convert the file reference to UNIX style
set this_path to the POSIX path of this_item
-- bring the target application to the front
tell application "iPhoto"
	activate
	try
		tell application "System Events"
			tell process "iPhoto"
				-- summon the import dialog
				click menu item "Import?" of menu "File" of menu bar 1
				-- enter the path to the image in the dialog input
				delay 2
				keystroke "G" using command down --uppercase G 
				delay 1
				keystroke this_path
				delay 1
				keystroke return
				delay 1
				-- click to start the import
				click button "Import" of window "Import Photos"
			end tell
		end tell
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try
end tell
--prompt for deletion of originals -may want to keep originals for separate editing or archiving
display dialog "Delete Originals?  WARNING--Do not click 'Yes' until Import is complete!" buttons {"Yes", "No"} default button 2
if button returned of the result is "Yes" then
	tell application "Finder" to delete items of this_item
end if

During execution, I get the [infamous] NSRecieverEvaluationScriptError: 4. The bizarre thing is, I still get the delete files prompt at the end of the script.
Can someone PLEASE tell me why this isn’t working? FWIW, the three dots after the “Import…” is an ellipsis, and not 3 periods.
Or, alternatively, if someone has a better way of automagically getting pics from the folder Image Capture saves them to into iPhoto, I’d be very open to suggestions.
Thanks,
Adam

Are you running Panther? Did you go to the Universal Access pref pane and “Enable access for assistive devices”? It’s required for GUI scripting. If the answer to both questions is yes, and assuming that you run the script in Script Editor, is a line of code highlighted/selected in Script Editor after the error occurs?

– Rob

Yes, I’m running Panther, and yes, access for Assistive Devices is enabled.

This works for me:

set this_item to ((path to "cusr") as string) & "Pictures:FromCamera:"
tell application "iPhoto" to activate
delay 1
tell application "System Events"
	tell process "iPhoto"
		keystroke "I" using command down --uppercase I 
		delay 2
		keystroke "G" using command down --uppercase G 
		delay 1
		keystroke (POSIX path of this_item)
		delay 1
		keystroke return
		delay 1
		keystroke return
	end tell
end tell
activate
if button returned of (display dialog "Delete Originals? WARNING--Do not click 'Yes' until Import is complete!" buttons {"Yes", "No"} default button 2) = "Yes" then tell application "Finder" to delete items of this_item

Jon

I just tested your script and it worked perfectly with iPhoto 2 in OS X 10.2.8. It seems that someone once suggested the following syntax for Panther scripts that issue keystroke commands. Does it help?

keystroke “G” using {command down}

– Rob

Jon-
Didn’t work for me. Now I get this: “Can’t get POSIX path of “Macintosh HD:Users:username:Pictures:FromCamera:”.”
Any suggestions?

Rob-
Still no dice. Same error, same behavior. BTW, I’m running Panther and iPhoto 4.

Thanks guys, I appreciate your input. Let’s keep pluggin’ and chuggin’.
–Adam

Sorry, I was trying to get too slick and changed the script after this worked for me:
set this_item to ((path to “cusr”) as string) & “Pictures:FromCamera:”
set this_path to POSIX path of this_item

tell application "iPhoto" to activate
delay 1
tell application "System Events"
	tell process "iPhoto"
		keystroke "I" using command down --uppercase I 
		delay 2
		keystroke "G" using command down --uppercase G 
		delay 1
		keystroke this_path
		delay 1
		keystroke return
		delay 1
		keystroke return
	end tell
end tell
activate
if button returned of (display dialog "Delete Originals? WARNING--Do not click 'Yes' until Import is complete!" buttons {"Yes", "No"} default button 2) = "Yes" then tell application "Finder" to delete items of this_item

Jon

jon-
Thanks, man, that worked…until the delete part. Leaving the variable in the delete items line as “this_item” resulted in this Applescript error when clicking “yes”: “Finder got an error: Handler can’t handle objects of this class.”
So I changed it to “this_path”, but now I get this when I click yes: “Can’t get every item of “/Users/adamwiseman/Pictures/FromCamera/”.”
Dangit. So close! Thanks for getting the first part to work, though!
–Adam

Does this work for deleting the files?

tell application "Finder" to delete items of folder this_item

– Rob

Rob–
That did the trick! :smiley:

Thanks to both jon and Rob for your help in getting this simple script working. For future reference, here’s the working script:

set this_item to ((path to "cusr") as string) & "Pictures:FromCamera:"
set this_path to POSIX path of this_item
tell application "iPhoto" to activate
delay 1
tell application "System Events"
	tell process "iPhoto"
		keystroke "I" using command down --uppercase I 
		delay 5
		keystroke "G" using command down --uppercase G 
		delay 1
		keystroke this_path
		delay 2
		keystroke return
		delay 2
		keystroke return
	end tell
end tell
delay 2
activate
if button returned of (display dialog "Delete Originals? WARNING--Do not click 'Yes' until Import is complete!" buttons {"Yes", "No"} default button 2) = "Yes" then tell application "Finder" to delete items of folder this_item