Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Needed: Script for exporting iPhoto albums into a file structure

Hello all! I have no experience with AppleScript, but I heard it should be possible to write a script which helps to copy/export a iPhoto album structure into an according directory structure. Does anybody already have such a script?
Thx for any information on that!

iMac g5 20 2GB, Mac OS X (10.4.5)

Posted on Apr 28, 2006 2:11 PM

Reply
19 replies

Apr 29, 2006 12:18 AM in response to Camelot

Hi Camelot,
I guess I have to say rather the entire library. For one single album, I can do it manually. But for an folder structure it would be a real big helper. I do have structures like "Year 2005 - Vacation - USA" and the folder "USA" finally holds several albums like "Colorado, Idaho, Utah etc". It would be real nice to have any programmm which allows me to export e.g. "Year 2005" on a different location on my hard drive without loosing the structure. Therefor, I guess the approach "entire Library" would better suite the need. Actually I was wondering why Apple did not put some kind of "drag'n'drop" into iPhoto. It would be great, if I could drag "Year 2005" from iPhoto out to the Desktop. 1000 Thx for your hints!

May 1, 2006 11:23 PM in response to Thomas Halenbeck

Thomas,

I have created an AppleScript along with the TextCommands OSAX that duplicates all of the albums in iPhoto to a folder called "Albums" on the desktop. It is quite slow because of the need to open an Info window in Finder to get the path to the original photo but gets the job done.

If you wish it could be modified to provide an ability to select individual albums for duplication. Let me know if you are interested in the latter. I am also seeing whether the album structure can be created directly in a burn folder so that CDs/DVDs can be rapidly burned.

TextCommands is donationware and available at the following location:

http://osaxen.com/files/textcommands1.0.1.html

and should be placed in the following location for the AppleScript to see it:

~/Library/ScriptingAdditions/


click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">property PathToDesktop : path to desktop as string
property PathToPictures : path to pictures folder as string
property PathToiPhotoLibrary : PathToPictures & "iPhoto Library"
property PathToiPhotoAlbums : PathToiPhotoLibrary & ":Albums"
property PathToCopiedAlbums : PathToDesktop & "Albums"

tell application "Finder"
activate
set theCopiedAlbumsFolder to duplicate folder (PathToiPhotoAlbums as alias) to desktop
set theAlbums to folders of folder PathToCopiedAlbums
set theExtraneousFiles to files of folder PathToCopiedAlbums
delete theExtraneousFiles
repeat with anAlbum in theAlbums
repeat with anAlias in anAlbum

-- need to use GUI access to grab the path to the original photo
open information window of anAlias
tell application "System Events"
tell process "Finder"
-- grab the path to the original file
set PathToTheOriginalPhoto to value of static text 2 of scroll area 1 of window 1
end tell
end tell
close window 1

-- need to remove some extraneous material and convert to AppleScript path format
tell application "TextCommands"
split PathToTheOriginalPhoto using {":", "../"}
set PathToTheOriginalPhoto to item 4 of the result
set PathToTheOriginalPhoto to search PathToTheOriginalPhoto for "/" replacing with ":"
set PathToTheOriginalPhoto to (PathToiPhotoLibrary & ":" & PathToTheOriginalPhoto) as alias
end tell

(* unfortunately there seems to be bug in duplicate file to another folder so must use a copy, , delete the alias, move, and clean up name of copied file sequence to accomplish the equivalent *)

-- duplicate the original in the original album folder
set theCopiedPhoto to duplicate PathToTheOriginalPhoto

-- Delete the alias in the Copied Album
delete anAlias

-- Move the copied photo to the Copied Album
set theCopiedPhoto to move theCopiedPhoto to anAlbum

-- Remove the "copy" from the photo names
set NameOfPhoto to name of theCopiedPhoto
tell application "TextCommands"
set name of theCopiedPhoto to search NameOfPhoto for " copy" replacing with ""
end tell

end repeat

end repeat
end tell</pre>

PowerBook 12" Mac OS X (10.4.6)

May 2, 2006 11:27 AM in response to lc55

Hi Ic55!
1000Thx for your help on that! Unfortunatly I did not get it going. May you can further assist me on that, please? I have absolutly no experience with AppleScript 😟
Here is what I did:
1) I downloaded textcommands. As I did not have a Folder "ScriptingAdditions", I created one under my HomeDir "/Users/thomas/Library/" and copied the executable "TextCommands" in there. BTW - would it work if I place it in "/Library/ScriptingAdditions" ?
2) Your provided link (great how it worked!) opened your script in my "Scripteditor". I replaced "PathToDesktop" with "/Users/thomas/Desktop/" and "PathToPictures" with "/Users/Shared/Bilder/". I have to say, that I keep my "iPhoto Library" there and my wife and me just have symbolic links in our HomeDirs pointing to that location.
3) I could save the script but executing it brought the error "/Users/Shared/Bilder/iPhoto Library/Albums" could not be found. The event protocol is showing that the script fails right in the first "set" line and it looks like the property "PathToiPhotoAlbums" is causing this. I checked it - when I take this path in "Terminal" I can "cd" there. The path is existent and I can walk over there - should be not a permissions problem.

Do you have any idea?
Thx again for your patience and your efforts on that!
Greetings from Germany!



iMac g5 20 2GB Mac OS X (10.4.5)

iMac g5 20 2GB Mac OS X (10.4.5)

iMac g5 20 2GB Mac OS X (10.4.5)

May 2, 2006 7:35 PM in response to Thomas Halenbeck

Thomas,

1) Either one of those locations should work. The first for only yourself and the latter for anyone using the computer.

2) Yes that comes in handy but I can't take credit for it as it came from another avid AppleScripter named Michael Henley.
I guess I should have given you more instructions. You shouldn't have to replace the "PathToDesktop" or "PathToPictures" as the command following the property are automatically resolved by the AppleScript to "~/Desktop" and "~/Pictures". If you have a symbolic link within the Pictures folder that should also be resolved.

3) However, your method of putting in the direct path description should also work as long as you put the path description in the AppleScript format (: used to separate items) instead of the Unix format (/ used to separate items). Give that a try and let me know if you still have problems.

May 3, 2006 9:22 AM in response to lc55

Hi Ic55!
Thx again for your help! I did not know about the ":" instead of the "/" when talking about AppleScript. I corrected it and that culprit was solved. I still had to manually set the property "PathToPictures", as it looks like the interpreter is not following the s-link. Now I got the script running w/o any error message. But there was no function either 😉
I just found one folder "Albums" on my Desktop, which holds another folder with the same name as one of my Albums (lets say "Granny"). I checked my iPhoto file structure and saw that this folder "Granny" was indead the one and only folder in "./iPhoto Library/Albums". Of course, I have lots of Albums and Folders in my iPhoto (Version 6). As Apple changed the directory structure from V5 to V6, is that may the reason? Is the script designed for V5?
Thx again for your help and your patience. I am surprised myself, that it looks like there is no Software available which is providing that functionality 😟


iMac g5 20 2GB Mac OS X (10.4.5)

May 3, 2006 4:37 PM in response to Thomas Halenbeck

Hi Thomas,

Good to hear that you were able to progress further.

Yes this script was built using iPhoto 5 however that shouldn't completely kill the concept of what is being attempted. Unfortunately I don't have access to iPhoto 6 so we are going to have to work together on this problem.

If I tell you in general terms the mental approach I took to try and solve the problem and what the AppleScript is doing we might be able to sort out how to adjust it to work with iPhoto 6.

When I read your request I went to where I knew the photos are stored by iPhoto 5 in the Users Pictures folder and continued to dig deeper into the file structure. I find the Albums folder matched the iPhoto folder structure contained within iPhoto and within each Album folder were the associated jpg images.

Using this knowledge I then decided to try copying the Albums folder to the Desktop and see what happened. The result was the retained Album structure with the images now replaced with aliases to the original file.

The remainder of the script just determines where the original file is located, duplicates that file, moves that duplicated file to the appropriate Album in the Desktop copy of the Albums, deletes the alias of that file, and removes the " copy" from the file name.

So if you try a similar approach that is dig into the file structure and see if there is a correspondence between what you see in iPhoto and the physical structure on the drive then we can contiue to use the approach I have given you and adjust it to match the path to the original photos. Since the structure seems to have changed you may have to do a search to find one of your originals in the Finder and then backtrack to determine the folder structure.

Good luck and please keep me informed on your progress. I love puzzles!

May 6, 2006 10:53 PM in response to lc55

Hi Ic55,
I have checked the file/directory structure of iPhoto 6 more detailed. While you find all "film rolls" as according directories in the file system, the entire structure of your albums and folders is stored in a file named "Library6.iPhoto". And this file has a partly binary format! Opening it in a text editor, you just can find the names of your albums, but no structure at all.
I guess it is just not possible to perform a "complex" export in iPhoto 6 ... 😟


iMac g5 20 2GB Mac OS X (10.4.5)

May 7, 2006 1:57 PM in response to Thomas Halenbeck

Thomas,

It does sound like they have moved completely to a database system although my iPhoto 5 set-up also includes a file called Library.iPhoto.

Is there still an Export... command in the File menu? This appears to be Apple's attempt to provide the functionality if not the method you propose to move the photos out of iPhoto.

If the Export remains then you will be able to accomplish what you want manually. This will allow you to select an album in the albums column of iPhoto and export all of the photos in that album to another location. You have a number of options available for formatting and naming the new file. Similar to the Save or Open dialog windows the Export dialog window allows you to move to the location on the drive you wish and create new folders. I can automate this process using AppleScript but need to resort to GUI manipulation methods which may need to be different in iPhoto 6. So until I can get access to iPhoto 6 I would recommend using the manual method which should get you started.

May 7, 2006 10:55 PM in response to lc55

Hi Ic55,
yes there still is that export command. I am aware about the chance to proceed an folder-export manually, but that is what I wanted to prevent. All information is available and all work was already done. It is hard to believe for me that a software like iPhoto does not provide such a functionality as its demand is obvious (imaging you want to switch to a different photo-programm one of these days!). Now it looks like using iPhoto is a one-way-street 😟
Anyhow, if you have any further idea, that would be fine! Thx again for your help on that. But please dont spend all your time on that! It looks pretty time consuming to me ...
Best regards from Germany. Thomas.

May 9, 2006 10:37 PM in response to Thomas Halenbeck

Thomas,

I was finally able to find a machine with iPhoto 6. Please find an AppleScript that uses GUI system events to automate the Export function. I did not want to use this type of method because it tends to be somewhat inconsistent from one computer to another. However other methods all seemed to lack some elements to provide a complete solution. Try it out and let me know if it works.

click here to open this script in your editor <pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">property StandardiPhotoAlbums : {"Library", "Last Roll", "Last 12 Months", "Trash"}
property DesktopAlbum : "iPhoto Albums"

tell application "Finder"
-- create a folder on the Desktop to hold the Album file structure
make new folder at desktop with properties {name:DesktopAlbum}
end tell

tell application "iPhoto"
activate
repeat with anAlbum in albums -- go through all the albums in iPhoto one at a time

select album (name of anAlbum) -- select the next album in iPhoto

if (name of anAlbum) is not in StandardiPhotoAlbums then -- check to see whether it is one of my albums or the iPhoto standards

tell application "System Events"
tell process "iPhoto"
-- Start the Exporting process
click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1
repeat until window "Export Photos" exists
end repeat
-- Move to File Export Panel and assume export defaults
click radio button "File Export" of tab group 1 of window "Export Photos"
click button "Export" of list 1 of window "Export Photos"
repeat until sheet 1 of window "Export Photos" exists
end repeat
-- Move to the folder that was created on the Desktop
click pop up button 1 of group 1 of sheet 1 of window "Export Photos"
repeat until menu 1 of pop up button 1 of group 1 of sheet 1 of window "Export Photos" exists
end repeat
click menu item DesktopAlbum of menu 1 of pop up button 1 of group 1 of sheet 1 of window "Export Photos"
repeat until ((exists of menu 1 of pop up button 1 of group 1 of sheet 1 of window "Export Photos") is false)
end repeat
-- Create a new folder within the Desktop created folder with the same name as in iPhoto
click button "New Folder" of sheet 1 of window "Export Photos"
repeat until window "New Folder" exists
end repeat
set value of text field 1 of window "New Folder" to (name of anAlbum)
click button "Create" of window "New Folder"
repeat until ((exists of window "New Folder") is false)
end repeat
-- Start Exporting photos to the new subfolder and wait for all the dialogs to close
click button "OK" of sheet 1 of window "Export Photos"
repeat until ((exists of sheet 1 of window "Export Photos") is false)
end repeat
repeat until ((exists of window "Export Photos") is false)
end repeat
end tell -- iPhoto
end tell -- System Events

end if

end repeat

display dialog "All finished exporting from iPhoto..."

end tell



</pre>



PowerBook 12" Mac OS X (10.4.6)

May 11, 2006 12:06 PM in response to lc55

Hi Ic55,
Thx again for your endurance on that issue!
I ran the script and got the following error:
--------------EventLog ---------------------------->
tell application "Finder"
make new folder at desktop with properties {name:"iPhoto Albums"}
folder "iPhoto Albums" of folder "Desktop" of folder "thomas" of folder "Users" of startup disk
end tell
tell application "iPhoto"
activate
count every album
200
get name of item 1 of every album
"Fotoarchiv"
select album "Fotoarchiv"
album id 4.295966296E+9
get name of item 1 of every album
"Fotoarchiv"
end tell
tell application "System Events"
click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1 of process "iPhoto"
"System Events got an error: NSReceiverEvaluationScriptError: 4"
<-----------------------------------------------
Any idea?

May 13, 2006 7:27 AM in response to lc55

Hi Ic55,
it resulted in the same error message. Bit the script was running for a longer time. Here is what I did:
1) checked the bix per your last post
2) Logged out and back in
3) opened your script per mouse click above in this thread
4) switched to the Event Log panel
5) clicked "run"
6) script was running, created a folder "iPhoto Albums" on my desktop and a file browsing dialog box opened after the "image export" box opened.
7) script stopped again with same error

Is that helpful to you?
Thx again!

Needed: Script for exporting iPhoto albums into a file structure

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.