different behavior when run from the editor or the AppleScript menu

Hi,
I wrote the following script that reads all the files in the foremost Finder window and marks with the red label all image files that don’t have any GPS information in EXIF, and clears the label of the image files that have.
NB : this script needs iMagine Photo from http://www.yvs.eu.com/imagine.html


tell application "Finder"
	set theFolder to folder of front window as alias
	set theFiles to every file of theFolder
end tell
set cptGPS to 0
set cptNoGPS to 0
repeat with eachFile in theFiles
	set theFile to eachFile as alias
	tell application "iMagine Photo"
		set avecGPS to false
		set thisImporter to import graphic theFile
		set exifData to the exif data of thisImporter
		close thisImporter
		
		repeat with i from 1 to the count of exifData
			set thisItem to item i of exifData
			set thisItemExifType to the exif type of thisItem
			--			display dialog "exiftype:" & thisItemExifType
			if thisItemExifType as string is "gps latitude" then
				set avecGPS to true
				exit repeat
			end if
		end repeat
	end tell
	
	tell application "Finder"
		if avecGPS then
			set theLabel to 0
			set cptGPS to cptGPS + 1
		else
			set theLabel to 2
			set cptNoGPS to cptNoGPS + 1
		end if
		set the label index of theFile to theLabel
	end tell
end repeat

display dialog "Found " & cptGPS & " pictures with GPS and " & cptNoGPS & " without."


This script can certainly be improved, but it works when run from the Script Editor.
But it doesn’t work when run from the AppleScript menu in the menu bar (after I copied the script to the /Library/Scripts or /Users/myname/Library/Scripts folder).

Do you have any idea what the problem is ?

Thanks
Manu

Model: iMac 24" 2.8GHz Max OS X 10.5.4
Browser: Firefox 3.0.1
Operating System: Mac OS X (10.5)

Does this much of it work?

tell application "Finder"
   set theFolder to folder of front window as alias
   set theFiles to every file of theFolder
end tell

Hi,

folder is actually no property of window, it’s better to use target,
btw: the alias coercion is useless

tell application "Finder"
	set theFolder to target of front window
	set theFiles to every file of theFolder
end tell
.

Unfortunately the result is the same.
Thank you for your answer anyway.

I noticed a difference in the output of the display dialog in bold thanks to the display dialog that was commented out in my sample.
When the script is run from the editor, the first dialog says exiftype:exif make but when it is run from the AppleScript menu, it says exiftype:«constant ****@mak» instead.
I don’t know why but it explains why my script fails : it can’t find the “gps latitude” property.

manu

That’s great. I still have lots of thing to learn about AppleScript :wink:

Merci Jacques !