Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to export iPhoto into SimpleViewer System
Hey, I really like SimpleViewer. It's a fast, free, and elegant way of putting together a Flash gallery. For proof, check out my own SimpleViewer gallery.

The only problem is, what if you store all your photos in iPhoto? What if you have ordered them, put them in galleries, given them descriptions, and now you want them in a web-based Flash gallery? And you don't want to pay anything?

Well, here is the solution. I have created a simple AppleScript that will do the heavy lifting for you. It will drop an existing iPhoto album into a new folder, export thumbnails and full-size images, and size them appropriately for SimpleViewer. It will even make sure your full-size images and thumbnails have the same filename. And it will write the SimpleViewer XML file for you.

What you need

You need a directory on your local machine that will serve as a repository for galleries. Download SimpleViewer. Put the flash_detect.js and viewer.swf files into this directory.

Then, use my AppleScript in Script Editor. First, select a gallery in iPhoto. Then run my script. You will be prompted for a directory; select the one you created earlier. Sit back and wait for the file copies to finish.

In addition to this, you'll also need my index.php file. This index file implements rudimentary support for multiple galleries, rendering a simple menu at the top of the page. If you put multiple galleries into this folder, index.php will pick them up.

Phew. Well, check out the results once again. Nifty.

[robg adds: I haven't tested this one...]
    •    
  • Currently 1.75 / 5
  You rated: 1 / 5 (4 votes cast)
 
[23,813 views]  

An AppleScript to export iPhoto into SimpleViewer | 15 comments | Create New Account
Click here to return to the 'An AppleScript to export iPhoto into SimpleViewer' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to export iPhoto into SimpleViewer
Authored by: whodisbe on Oct 24, '05 07:49:08AM

Great tool! I had a bit of trouble getting it to work, but soon found out why. The script works exactly as promised. The only "bug" is that if an Album has spaces in the name (for example "joe and jane's wedding") when it creates the XML file it doesn't add the %20 in place of the spaces causing the SimpleViewer album to get stuck in the "loading XML data" step.

Other than that, tool works great! I've been looking for something like this ever since I discovered simple text.



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: kevin_C on Oct 24, '05 11:11:45AM

I attempted, but could not get success. The script returns an error-"NSCannotCreatScriptCommand"- are there version requirements? I have older iPhoto... as I am a novice at scripting/flash/xml, I do not know how to de-bug...



[ Reply to This | # ]
NSCannotCreateScript Error fixed!
Authored by: finnpage on Nov 12, '05 05:05:52PM

I was having the same error. I have iPhoto 4 and OS X 10.3.9
I finally found a fix by changing two lines in the script referring to the POSIX path of the image and thumbnail files. I also changed the caption from the title of the picture to the caption of the photo. Here is the new version of the script.

[code]
tell application "iPhoto"

set album_name to name of current album
tell application "Finder"
set main_output_folder to choose folder with prompt "Please select output folder"
end tell

tell application "Finder"
if not (exists folder album_name of main_output_folder) then
make new folder at main_output_folder with properties {name:album_name}
end if

set album_name to folder album_name of main_output_folder

if (not (exists folder "thumbs" of album_name)) then
make new folder at album_name with properties {name:"thumbs"}
end if

if (not (exists folder "images" of album_name)) then
make new folder at album_name with properties {name:"images"}
end if
end tell


set album_photos to every photo of the current album

set output to "<?xml version='1.0' encoding='UTF-8'?><SIMPLEVIEWER_DATA maxImageDimension='800' textColor='0xFFFFFF' frameColor='0xFFFFFF' bgColor='0x181818' frameWidth='20' stagePadding='20' thumbnailColumns='2' thumbnailRows='5' navPosition='right' navDirection='LTR' title='" & name of current album & "' imagePath='" & name of current album & "/images/' thumbPath='" & name of current album & "/thumbs/'>" & return

repeat with i from 1 to the count of album_photos

set my_photo to item i of album_photos

-- ****** next two lines are new
set photo_path to (image path of my_photo)
tell application "Finder" to set photo_file to ((POSIX file photo_path) as alias)
set photo_filename to image filename of my_photo

-- ****** next two lines are new
set thumb_path to (thumbnail path of my_photo)
tell application "Finder" to set thumb_file to ((POSIX file thumb_path) as alias)
set thumb_filename to thumbnail filename of my_photo


tell application "Finder"
set thumbs_folder to folder "thumbs" of album_name

if (exists item thumb_filename of thumbs_folder) then
delete item thumb_filename of thumbs_folder
end if

if (exists item photo_filename of thumbs_folder) then
delete item photo_filename of thumbs_folder
end if

duplicate thumb_file to thumbs_folder
set name of (file thumb_filename of thumbs_folder) to photo_filename

set new_thumb to (file photo_filename of thumbs_folder) as string

tell application "Image Events"
close images
set thisImage to open new_thumb
scale thisImage to size 60
save thisImage
end tell

set photo_folder to folder "images" of album_name

if (not (exists item photo_filename of photo_folder)) then
duplicate photo_file to photo_folder with replacing
end if

set new_photo to (file photo_filename of photo_folder) as string
tell application "Image Events"
close images
set thisImage to open new_photo
scale thisImage to size 800
save thisImage
end tell

end tell

-- ****** 'comment' was 'title'
set output to output & "<image><name>" & photo_filename & "</name><caption>" & comment of my_photo & "</caption></image>" & return as string

end repeat

set output to output & "</SIMPLEVIEWER_DATA>" & return as string


set output_filename to album_name as text
set output_filename to output_filename & "imageData.xml"

my write_to_file(output as string, output_filename, false)


end tell

on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to open for access file target_file with write permission
if append_data is false then set eof of the open_target_file to 0
write this_data to the open_target_file --starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
[/code]

Matt



[ Reply to This | # ]
NSCannotCreateScript Error fixed!
Authored by: mr Grinners on Jan 11, '06 04:24:37AM

Sorry to be ignorant never really done the script editing before but which script do you need to edit? the app itself? or do you create a new script? (which i tried and tested and works fine) but how do i get this to work with the iphotoexport app???

Thanks

Damien



[ Reply to This | # ]
NSCannotCreateScript Error fixed!
Authored by: mr Grinners on Jan 11, '06 05:23:05AM

I got the script working now but cant get the photos to load properly, keeps coming up with what looks js errors and the photos dont load into the viewer properly..... any ideas???

Cheers



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: bobmax48 on Oct 24, '05 11:56:45AM

The script works for me but when I try to use it on the web I get an error in the activity window that it can't find the imageData.xml file. All of the files seem to be in the right place, not sure why this is not working.



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: hagus on Oct 24, '05 02:15:01PM

Hi all. As pointed out in an earlier comment, there may be a bug with spaces in album names. I actually didn't see that bug on my local test machine, but it would be easy to fix. Next problem is that I am running on the very latest OS X and iLife suite - some of the features I leveraged may not be available in older software releases!

What I will probably end up doing is wrapping this in a nice GUI with a progress bar and album drop down selector, to make it a bit more usable.



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: tanvach on Oct 24, '05 03:52:21PM

I have been looking for a simple flash based gallery builder for a long time, and this is definitely a very promising development. I have found web based galleries are just too ugly (i.e. gallery.menalto.com) and ready made flash applets too involved. I hope you can iron out the problems, and a gui will definitely be a big plus!



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: whodisbe on Oct 25, '05 05:52:16AM

Awesome! Looking forward to the GUI version with the features you mentioned.



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: wirehead on Oct 24, '05 08:03:58PM

SO CLOSE!

Now someone make an applescript that will EXPORT all folders, and create a flat dir system of each folder being a directory, and inside the pictures.

THen I can share that with the xbox!



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: giulio on Oct 27, '05 09:42:04AM

The problem is that the script is not placing imageData.xml into the correct directoty. Just make sure these two lines of code look like:

---------------------------------
set output_filename to main_output_folder as text
set output_filename to output_filename & "imageData.xml"
---------------------------------

---
Headrest Embroidery: http://www.headrestembroidery.com



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: hagus on Oct 28, '05 06:34:37PM

Just letting everyone know that I have updated this AppleScript to include a GUI! Check out all the details on my webpage.

Regards, Luke.

[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: pix2pixels on Nov 27, '05 11:49:59PM

Luke,
Great application.
It works well with osx10.4.3!
I cannot open the index.phps.gz file ypu mentioned in the previous post. Could you rwpost it again with different compression?
Thank you



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: pix2pixels on Nov 27, '05 11:51:51PM

Luke,
Great application.
It works well with osx10.4.3!
I cannot open the index.phps.gz file you mentioned in the previous post. Could you repost it again with different compression?
Thank you



[ Reply to This | # ]
An AppleScript to export iPhoto into SimpleViewer
Authored by: redfitz on Oct 28, '06 12:44:47PM

Can this be made to work with an Aperture album? Or with any folder of collected images on your computer? That would be great!

Nick



[ Reply to This | # ]