Strange behavior with this script

Hi there!

Very quick question. I’ve completed my first extremely simple AppleScript (well, actually the script is run in an automator app because I didn’t know how to implements drag&drop with the script, but that’s not the point).

Here’s the script


property image_extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg", "jpeg", "bmp"}
property video_extension_list : {"avi", "mov", "mpg", "mpeg", "wmv", "mkv", "m4v", "srt"}
property audio_extension_list : {"mp3", "wav", "mp4", "aac", "m4a", "m4b"}
property application_extension_list : {"dmg", "hqx", "toast", "app"}

on run {input, parameters}
	repeat with a from 1 to length of input
		set theCurrentFile to item a of input
		set theExtension to name extension of (info for theCurrentFile)
		
		if theExtension is in application_extension_list then
			tell application "Finder"
				move theCurrentFile to path to applications folder as string
			end tell
		else if theExtension is in image_extension_list then
			tell application "iPhoto"
				import from theCurrentFile
			end tell
			delay 1
			tell application "Finder"
				delete theCurrentFile
			end tell
		else if theExtension is in audio_extension_list then
			tell application "iTunes"
				add theCurrentFile to playlist "Library" of source "Library"
			end tell
			delay 1
			tell application "Finder"
				delete theCurrentFile
			end tell
		else if theExtension is in video_extension_list then
			tell application "Finder"
				move theCurrentFile to path to movies folder as string
			end tell
		else
			tell application "Finder"
				move theCurrentFile to path to documents folder as string
			end tell
		end if
	end repeat
end run

It just put the files that are dropped into it in the correct place.
The problem is that, whenever I use the app (whether is by dropping a file or just clicking on the icon) iPhoto is launched. It doesn’t matter the file’s extension, iPhoto will be opened always.

Why is this? iPhoto should only be opened if the file’s a picture.

Thanks!!

iPhoto is probably not one of the apps that exposes its AppleScript Dictionary to the AppleScript runner without being opened. To compile your file, it opens iPhoto.

I see…so basically I can’t do anything about it. It’s annoying to see iPhoto’s icon jumping in the dock when I use the script:)

Is there any other way to add files to my photo library without using iPhoto in the apple script? I guess not, but who knows…

Thanks Adam.

You could try circumlocuting the ‘tell application “iPhoto”’:

	.
else if theExtension is in image_extension_list then
	set iPhoto to "iPhoto"
	using terms from application "iPhoto"
		tell application iPhoto to import from theCurrentFile
	end using terms from

	.