Re: Why does this iPhoto applescript fail to produce new albums with photos in them?
Re: Why does this iPhoto applescript fail to produce new albums with photos in them?
- Subject: Re: Why does this iPhoto applescript fail to produce new albums with photos in them?
- From: kai <email@hidden>
- Date: Thu, 10 Mar 2005 20:47:47 +0000
On Thu Mar 10, 20051:13:44 am Europe/London, Andrew T. Lynch wrote:
Hello as gurus,
I want to automatically create albums of 48 (the current iphoto home page limit) images from a larger selection, which I will then publish to my home page. This script seems to run, but the resulting albums created have no images in them. I tried doing this adding one image at a time to the new albums, and it worked, but it took 6 seconds per image added (on a 1Ghz pbook).
Any Clues?
Thanks Much,
Drew
tell application "iPhoto"
set albumcount to 0
copy (my selected_images()) to the thePhotos
if the thePhotos is false then error "Please select some images."
set theCount to the count of thePhotos
set iStart to 1
set iEnd to 48
repeat while iStart is less than or equal to theCount
set albumcount to albumcount + 1
set albumname to "Page " & albumcount
new album name albumname
set theAlbum to album albumname
if iEnd is greater than theCount then
set iEnd to theCount
end if
add (items iStart thru iEnd of thePhotos) to theAlbum
set iStart to iStart + 48
set iEnd to iEnd + 48
end repeat
end tell
on selected_images()
tell application "iPhoto"
try
-- get selection
set these_items to the selection
-- check for single album selected
if the class of item 1 of these_items is album then error
-- return the list of selected photos
return these_items
on error
return false
end try
end tell
end selected_images
- Andrew T. Lynch
- Chief Zymurgist
- Verisity Design Inc.
Looks as if all the gurus are otherwise engaged, Andrew - so I'm afraid you'll have to make do with me for the moment...
Seems to me that it's not possible to add a list of photos (at least not here: iPhoto 4.0.3) - in which case you're apparently stuck with iterating through a list. That said, a repeat loop shouldn't be *that* much slower.
You mention trying to add one image at a time to the new albums but, since the exact method wasn't included, it's hard to say whether the sluggish performance is down to the scripting or iPhoto itself. I've looked at the issue here, and the results I get are significantly faster (on a slower machine) than yours. However, I'm testing with relatively few photos of moderate size - which might have a bearing on the situation.
I noticed some slightly quirky behaviour in all this (which you may have already seen yourself).
For one thing, when the selection is an album, nothing is returned when attempting to get the class - resulting in an error. (When photos are selected, the 'photo' class is returned correctly.) Indeed, that may be why your script used a try block in the first place. It's certainly why I've retained it in the suggested script below.
Another minor niggle is that, even though the 'name' parameter must be included, the 'new album' command returns a completely useless value:
> album "" of application "iPhoto".
Again, your own script worked around this - as does my suggestion - with the inclusion of an extra line or two.
Frankly, I'm not entirely sure if the following will improve matters for you. If it doesn't, then I doubt you'll speed things up significantly with things as they stand. Still, it might be worth a go...
--
: 48 (* modify as required: maximum 48 *)
()
"iPhoto" ( )
1's
current application display dialog "Please select some images first." {"Cancel"} default button 1 with icon 0
()
( )
"iPhoto" 1
+ - 1 >
"Page " & + 1
new album
's
--
Anyway, I've certainly learned something from all this. For one thing, I now know what a zymurgist does... ;-)
http://www.guardian.co.uk/guardianeducation/story/0,3605,512216,00.html
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden