iphoto open selected movies

I am trying to write a script to open selected iphoto movies in quicktime and save them as mp4. The script however keeps opening the same movie over and over. I’ve put in a dialog box that displays the current photoID and that changes as expected, but the first movie keeps opening. Any suggestions?
Thanks


set sl to ((choose folder with prompt "Save converted movies to:") as text)
tell application "iPhoto"
activate
set origMovs to selection
end tell
repeat with this_item in origMovs
tell application "iPhoto"
activate
set this_id to id of this_item
display dialog this_id
--the id keeps changing but the same movie keeps opening
--I assume it is to do with 'select this_id' since all the movies are already selected.
--is there another way to open the movie in Quicktime?
select this_id
set view to edit
end tell
tell application "QuickTime Player"
activate
set save_location to sl & (get name of movie 1) & ".mp4"
export movie 1 to save_location as MPEG4 using most recent settings
close movie 1 saving no
end tell
end repeat


Ciao,
I guess this happens because you never indicate to QTPlayer what file it should open. Maybe this example will help you to implement the QuickTime part correctly:

tell application "iPhoto"
	activate
	set s to selection
	repeat with this_item in s
		set f to image path of this_item
		set f to POSIX file f as alias
		tell application "QuickTime Player"
			activate
			open f
			-- do your QT conversions here
			close movie 1
		end tell
	end repeat
end tell

Good scripting
Farid

Farid,
Thanks for the suggestion. I think that I’ve tried that before, but found that ‘image path’ returned the path to the thumbnail .jpg file for the movie, instead of the movie itself, which is why I changed to using ‘set view to edit’ which opens the currently selected movie in Quicktime.
I’ll give it another go when I’m home this evening though.
Does anyone have any other suggestions?
Is there a way to deselect the initial selection before selecting this_id?
Thanks
Ben

This is true for images. However movies return a .jpg when asked for their image filename or image path

Has anyone found a way to distinguish movies?

-Luke

added: when I set view to edit on movies, they are opened in QuickTime

Hi Luke,

on my machine, a keyword “Film” is added automatically for each imported iPhoto movie.
This returns all photos with a keyword “Film”

tell application "iPhoto" to set moviePhotos to photos whose name of keywords contains "Film"

Hoi Stefan,

Thanks for the tip.
l suspect that you are using German on your system.
Mine is localized to English. The keyword added is Movie instead of Film.

  • Luke

Stefan:

Your scriplet:

tell application "iPhoto"
	set moviePhotos to photos whose name of keywords contains "Movie"
	(item 1 of moviePhotos)'s image path
-->"/Volumes/Ricoh/Master/Master Library/Modified/2006/Roll 2/CraigSnow_2.jpg"
end tell

does a great job of finding the movies in iPhoto, but as you can see, it still returns the image path to the “cover frame” of the movie, NOT to the image path of the movie file.

I am trying to figure out a way to script access to the actual movie file location. Has anyone figured that out yet? My experimentation makes it seem impossible from within iPhoto.

Here’s a small work-around for your problem. This assumes you have the movie selected in iphoto. This will get you the posix path to the movie.

tell application "iPhoto"
	set iphoto_selection to selection
	set image_name to image filename of (item 1 of iphoto_selection)
end tell

set baseName to (text items 1 thru -5 of image_name) as string
set movieName to baseName & ".mov"
set the_results to do shell script "mdfind -onlyin " & quoted form of POSIX path of (path to pictures folder) & " " & quoted form of movieName