Import Pictures to iPhoto

I found a script on one of Apple’s pages that says it uses the new GUI scripting to get iPhoto to import images automatically. The script it gave was:


 display dialog "Import an image file or a folder of images:" buttons {"Cancel", "Folder", "Image"} default button 3
 if the button returned of the result is "Folder" then
      set this_item to choose folder
 else
      set this_item to choose file of type {"JPEG"}
 end if
 -- 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
                     set the value of text field 1 of group 1 of group 2 of window "Import Photos" to this_path
                     delay 1
                     -- click to start the import
                     click button "Import" of window "Import Photos"
                     if the last character of (this_item as string) is ":" then
                          -- it's a folder so click the import button again
                          click button "Import" of window "Import Photos"
                     end if
                end tell
           end tell
           on error error_message
           display dialog error_message buttons {"OK"} default button 1
      end try
 end tell

I can’t get this script to work, though, and I can’t figure out why. If I can get it to work, I need to change it a little bit. What I need to do is attach a folder action to a folder such that any pictures added to that folder would be automatically imported into iPhoto. Any suggestions?

You’ve installed the GUI scripting beta, right? Have you gotten any of the GUI scripting to work?

Jon

This was the first time I’ve tried the GUI scripting, and I can’t seem to get any of it to work.

Did you go to the Universal Access pref pane and “Enable access for assistive devices”? It’s required for GUI scripting.

– Rob

We really need to make this a sticky topic. Rob, do you have an autofill preference for the Universal Access line? You should for the number of times it’s been entered. (A search on “Universal Access” on this board results in 13 topics.)

Jon

LOL. It’s funny that you mention autofill because as I typed the line in my response, I considered entering it into Spell Catcher as a shorthand entry. I think I’ll do that now. :wink:

– Rob

I’m trying to do the same thing and it gets to the Open dialog, then says NSReceiverEvaluationScriptError: 4.

I’m not sure, but I think that that script, as written, does not work on Panther and/or iPhoto 4. It has to do with the GUI elements that are being scripted. If you’re using either one of those, then you’ll need to tweak it. I think I have a working version, and I’ll dig around for it. But, FWIW, this script does nothing more than open the import dialog for you, and then, prompts you to either select a folder or individual picture. IMHO, it’s not worth the bother. Clicking Command-I from within iPhoto is just as easy (since this is essentially what the script does). I’ve been struggling with a better import method for months now, to little avail. Like I said, I’ll dig around my archives, as I think I might have a better script for you.
And as for GUI Scripting Beta, and Universal Access, the script doesn’t work even with those installed/enabled. Like I said, it has to do with the GUI changes made to the Import dialog of Panther and/or iPhoto4.