I want to have an Applescript on Mac OS X import a JPEG photo into
iPhoto2. I want a solution that does not involve UI Scripting (i.e.
no fair saying 'tell application "System Events"') or other software
that isn't in a base system install in Mac OS X 10.2. The iPhoto 2 Applescript
dictionary indicates that there is an 'add' command, but I have
not succeeded in getting it to import anything. No frills needed;
just a working code snippet. |
Request for Question Clarification by
supermacman-ga
on
26 May 2003 18:03 PDT
Would an AppleScript that imports images dragged-and-dropped onto the
script icon be satisfactory as an answer?
|
Request for Question Clarification by
supermacman-ga
on
26 May 2003 18:05 PDT
also note that this AppleScript requires OS X 10.2.3.
|
Request for Question Clarification by
arimathea-ga
on
26 May 2003 18:11 PDT
noswadj,
I'm pretty sure this is impossible without GUI Scripting. The
consensus seems to be that because iPhoto is (get this!) an
Applescript Studio application (Apple appears to have written it in
primarily AppleScript) you can't use the add command directly. Not
sure if this is reliable information, but I see it from several
sources.
|
Request for Question Clarification by
supermacman-ga
on
26 May 2003 19:32 PDT
You are right. In fact, the script I had found does rely on GUI
Scripting (and System Events)... therefore it does not satisfy the
criteria of the answer.
Here it is for your reference.
http://www.apple.com/applescript/GUI/index.html#1000
http://www.apple.com/applescript/GUI/index.html#1008
|
Clarification of Question by
noswadj-ga
on
26 May 2003 20:11 PDT
supermacman-ga,
Requiring OS X 10.2.3 (or 10.2.6 for that matter) is okay.
arimathea-ga,
Sigh. iPhoto drives me nuts. It's not quite usable, but with its
tight iLife integration, it is also the single photo application that
I must have working. Aargh! I'll hold out hopes that there is some
hidden way of doing imports with real Applescript -- what a basic
piece of functionality for Apple to overlook. My last resort will be
writing an Objective-C program to read/write AlbumData.xml and the
data directories directly to do the "import" manually; the System
Events is clunky and will never be fast or reliable.
|
Request for Question Clarification by
arimathea-ga
on
27 May 2003 07:24 PDT
noswadj,
Progress.
The following AppleScript is (C) 2003 Apple, and is included in that
package of scripts:
tell application "iPhoto"
activate
try
set the album_list to the name of every album
set this_ablum to (choose from list album_list with prompt "Pick the
album to delete:") as string
if this_ablum is "false" then error number -128
display dialog "Are you sure you want to delete album ?" & ¬
this_ablum & "? and its contents?" & ¬
return & return & ¬
"This action cannot be undone." buttons {"Delete", "Stop"} default
button 2 with icon 2
if the button returned of the result is "Stop" then error number
-128
set the photo_count to the count of photos of album this_ablum
if the photo_count is 0 then error "The chosen album contains no
photos."
with timeout of 1800 seconds
repeat with i from the photo_count to 1 by -1
add photo i of album this_ablum to trash album
You will notice the last line is 'add photo i of album this_ablum to
trash album'
There is also a photo class (obviously) with parameters of image path
and image filename.
Does this serve as a suitable answer (and get you far enough down the
path?)
-- arimathea-ga
|
Clarification of Question by
noswadj-ga
on
27 May 2003 09:23 PDT
arimathea,
The code snippet you gave manipulates a photo object that is already
in the library. How do I get a photo object reference when the photo
isn't in the library yet? The application has a 'photo' element on it
that can select elements, but when I look at the script dictionary, it
doesn't seem to have a way to reference photos by external filename.
|
Request for Question Clarification by
arimathea-ga
on
27 May 2003 11:26 PDT
It would seem to me (perhaps erroneously) that the class photo has
image filename and image path attributes. I'm not very
well-acquainted with AppleScript, but couldn't you use these two
attributes to do what you want? iPhoto Dictionary, scroll down to
iPhoto Suite, and 'class photo' has the attributes specified.
|
Clarification of Question by
noswadj-ga
on
27 May 2003 12:33 PDT
arimathea,
Yes, photo has those attributes. The difficulty is that they are
attributes that may be fetched from existing objects, not constructors
for building a new photo object. I still can't see how to build a new
photo object from a file that isn't already in the library.
|
Request for Question Clarification by
arimathea-ga
on
27 May 2003 12:51 PDT
noswadj-ga,
Sorry I couldn't be of more help. The only other thing I can thing of
is some jerry-rigged Image Capture->iPhoto transfer.
Best of luck.
--a
|