Re: question about iPhoto scripting
Re: question about iPhoto scripting
- Subject: Re: question about iPhoto scripting
- From: kai <email@hidden>
- Date: Thu, 3 Mar 2005 21:02:26 +0000
On Tue, 1 Mar 2005 15:20:04 -0600, Jonathan E Brassow wrote:
I have a webserver running on my mac. I'd like to make a script that
will:
1) query the user for a photo group name (pgname)
2) create a dir called pgname in /Library/WebServer/Documents
3) Export a specific album in iPhoto, via web page format to that dir
4) Alter the index.html file to include the reference to the exported
iPhoto album
1. is handled by display dialog
2. is handled by finder
4. is handled by a perl script via terminal (perhaps I could get this
done in AS at some point)
#3 is the hard one... I can open iPhoto and select the album, but I
can't export it.
Any ideas?
I don't recall seeing a flurry of responses to this one, Jonathan - so
perhaps I might have a crack at it...
P.S. I don't have iLife '05. I have whatever is the latest before that.
Neither do I yet, so I guess we're talking iPhoto 4 (4.0.3, here - for
the record).
Hmm... I think I see the problem you're grappling with. While an import
command exists, it looks as if no export event is available in iPhoto's
AS dictionary. Without that, it's not going to be easy to come up with
an elegant solution - and, as far as I can tell, all you can do in the
meantime is to script iPhoto's GUI.
The matter is complicated still further by some of the more deeply
nested UI elements on the export browser sheet, which seem (OMM at any
rate) reluctant to respond to events like 'click', 'select', etc. If
your experience is similar, you may have to resort to a bit of
keystroke subterfuge - as I've done. Anyway, the effort below seems to
do the job here (up to your stage #3), so you could try using it as a
starting point. (Any lines abutting the left-hand edge of the page may
need to be rejoined with the previous line.) Sorry about the length...
--------------
on cleanName(n)
set d to text item delimiters
set text item delimiters to ":"
set n to n's text items
set text item delimiters to "-"
set n to n as string
set text item delimiters to d
n
end cleanName
on uniqueName for currName at targetFolder
set n to 1
set newName to currName
tell application "Finder" to tell folder targetFolder to repeat while
exists folder newName
set n to n + 1
set newName to currName & space & n
end repeat
newName
end uniqueName
to chooseAlbum()
tell application "iPhoto"
set albumList to name of albums
set currAlbum to name of current album
end tell
tell (choose from list albumList with prompt "Please choose an iPhoto
album to export :" default items {currAlbum} OK button name "Export")
if it is false then error number -128
set chosenAlbum to item 1
end tell
tell application "iPhoto" to select album chosenAlbum
cleanName(chosenAlbum)
end chooseAlbum
to makeFolder out of currName at targetFolder
set newName to currName
repeat
set newName to cleanName((display dialog "Please enter a new photo
group name:" default answer (uniqueName for newName at targetFolder)
with icon 1)'s text returned)
try
if (count newName) is 0 then error number 5000
tell application "Finder" to tell folder targetFolder to set
fldrExists to exists folder newName
if fldrExists then
beep
if (display dialog "The photo group \"" & newName & "\" already
exists. Replace the existing files in that group?" buttons {"Cancel",
"Replace", "Don't Replace"} default button 3 with icon 2)'s button
returned is "Don't Replace" then error number 5000
tell application "Finder" to tell folder targetFolder to delete
items in folder newName
else
tell application "Finder" to make new folder at folder
targetFolder with properties {name:newName}
end if
exit repeat
on error number 5000 (* next repeat *)
end try
end repeat
newName
end makeFolder
to exportAlbum into newFolder at parentFolder
set tabKey to tab
set fullPath to POSIX path of parentFolder & newFolder
tell application "System Events" to tell process "iPhoto"
set frontmost to true
keystroke "e" using {command down, shift down}
tell window "Export Photos"
repeat until exists
end repeat
tell tab group 1
tell radio button "Web Page" to if value is 0 then
click
repeat until value is 1
end repeat
end if
tell group 1 to tell group -1 to tell text field -1 to set value
to newFolder
end tell
tell list -1 to click button "Export"
tell sheet 1
repeat until exists
end repeat
tell group -1
tell group 1 to tell text field 1 to set changeFocus to focused
tell browser 1
tell scroll area 1 to tell radio group 1 to if changeFocus then
keystroke tabKey
repeat until true is in focused of every static text
end repeat
end if
keystroke space
repeat until (count scroll areas) > 1
end repeat
end tell
keystroke tabKey
tell group 1 to tell text field 1
repeat until focused is true
end repeat
set value to fullPath
confirm
repeat until (count value) < 2
end repeat
end tell
end tell
click button "OK"
end tell
repeat until not (exists)
end repeat
end tell
end tell
end exportAlbum
set parentFolder to (path to "dlib" from local domain as Unicode text)
& "WebServer:Documents:"
set currName to chooseAlbum()
set newFolder to makeFolder out of currName at parentFolder
exportAlbum into newFolder at parentFolder
beep
tell application "iPhoto" to display dialog "The export operation has
been completed." buttons {"OK"} default button 1 with icon 1 giving up
after 3
--------------
---
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