Weird Image Events path problem

Well, weird to me anyway…

Consider this code, please:

on makeImageFiles(sourceFile, imageCounter, thumbSize, finalSize)
tell application “Finder”
open sourceFile
end tell

tell application "Image Events"
	set thisImage to open sourceFile

The Finder Tell block opens sourceFile with no problem. But then when image events tries to open the same file, it generates a file not found message.

Even stranger: this routine is part of a larger program. In some cases “sourceFile” is being pulled from an iPhoto catalog, and in other cases, it’s being pulled from an iView MediaPro folder. It’s only when coming from iView that the problem described above occurs.

Please help!

Clearly the relevant part is not the code you posted, but the part of the code that calls it.

Since you’re passing ‘sourceFile’ into the ‘makeImageFiles’ handler you need to examine just what ‘sourceFile’ is. For example is it a string? a path? an alias? Heck, for all we can tell from here it might be an integer.

Obviously iPhoto is passing in one class of object where iView is passing in some other class.

In some cases the Finder can coerce one object type to another but it’s likely that Image Events wants an alias, and nothing but an alias and that’s why it’s breaking.

Well, sourceFile is a path to a file that I grabbed out of iView. I’ve already tried coercing it into an alias, text, and anythign else I can think of, but I always get the same error message.

Here’s where I build a list of files from iView:

	set theSelection to the selection of catalog 1
	set theFiles to {}
	repeat with i from 1 to the count of theSelection
		set thisFile to the path of item i of theSelection
		set the end of theFiles to thisFile

I then loop with a repeat loop through theFiles, and pass each file to the routine I posted earlier.

Sounds like it could be a path style error. Different applications and methods take one of two types of paths… either colon-delimited or slash-delimited (posix). If you know that a path of some kind is being sent but not sure which, you’ll need to figure out what style is being sent, so you can coerce to the other if necessary. You could try logging the lines that are giving you trouble, or you could do something like the following…

--tell application "Finder"
--open sourceFile
--end tell
display dialog (sourceFile as string)

--tell application "Image Events"
--set thisImage to open sourceFile
display dialog (sourceFile as string)

This will pop up a dialog, who’s contents should be either…
“/path/to/some.file” → posix
“Mac HD:path:to:some.file” → colon

If the two are different, you should determine which one you need, and then coerce it to the other style…

set sourceFile to (posix file sourceFile) (* posix >> colon *)
set sourceFile to (posix path of sourceFile) (* colon >> posix *)

Hope that helps…

That’s the part that was confusing me, when I’d look at the string that was getting passed, it was a perfectly normal, colon-delimited text string. The iView dictionary says that paths are “international text.” Not sure if this is the same as “unicode” text.

I tried coercing into posix paths and strings and aliases and files, in several different places. I finally got it to work by doing this as soon as I grab a file name from iView:

set thisFile to the path of item i of theSelection
tell application “Finder”
file thisFile
end tell
set the end of theFiles to thisFile as alias

Still don’t quite understand why it’s being so picky.