Moving files by name with AppleScript Application

With the help of others that have come before, I have had some success with a file mover application. But I am now experiencing a strange behavior that I hope someone can help with.

The mover app works great except that it will not process one file. If I add multiple files it works. But just one, nope. If I add an additional file to the original one, both will go through.

Any help is greatly appreciated. See script below.

Thank you,

Kris

kristopherjulius@gmail.com

Here is the script I am running.




property One : "Macintosh HD:Users:munjulik:Desktop:One:" as alias
property Two : "Macintosh HD:Users:munjulik:Desktop:Two:" as alias
property Three : "Macintosh HD:Users:munjulik:Desktop:Three:" as alias
property ErrorIn : "Macintosh HD:Users:munjulik:Desktop:ErrorIN:" as alias
property FileIn : "Macintosh HD:Users:munjulik:Desktop:Review Images:" as alias




on idle
	try
		tell application "Finder"
			set theFiles to files of entire contents of FileIn
			repeat with indvFile in theFiles
				set fileName to name of indvFile as text
				try
					if fileName contains "one_" then
						move indvFile to One with replacing
					else if fileName contains "two_" then
						move indvFile to Two with replacing
					else if fileName contains "three_" then
						move indvFile to Three with replacing
					else
						move indvFile to ErrorIn with replacing
					end if
				end try
			end repeat
		end tell
	end try
	return 10
end idle



Hi,

Try this:

property One : "Macintosh HD:Users:munjulik:Desktop:One" as alias
property Two : "Macintosh HD:Users:munjulik:Desktop:Two" as alias
property Three : "Macintosh HD:Users:munjulik:Desktop:Three" as alias
property ErrorIn : "Macintosh HD:Users:munjulik:Desktop:ErrorIN" as alias
property FileIn : "Macintosh HD:Users:munjulik:Desktop:Review Images" as alias

try
	tell application "Finder" to set theFiles to files of FileIn
	set theList to files of theFiles
	repeat with aFile in theFiles
		set filename to name of aFile as text
		try
			if filename contains "one_" then
				move aFile to One with replacing
			else if filename contains "two_" then
				move aFile to Two with replacing
			else if filename contains "three_" then
				move aFile to Three with replacing
			else
				move aFile to ErrorIn with replacing
			end if
		end try
	end repeat
end try

– Peter –

When I tested code similar to the above with FIleIn referring to a folder with only a single file, I found that Finder returned a result that is not a list of a single item, but the single item itself. I would have expected (and indeed, the loop in the the full program expects) that theFiles is always a list. My guess is that this is probably a long standing bug in Finder that can not be fixed due to some programs depending on the behavior (backwards compatibility). We can work around it by always making sure we have a list.

Put if class of theFiles is not list then set theFiles to {theFiles} after theFiles is initialized.

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari Version 4 Public Beta (4528.16)
Operating System: Mac OS X (10.4)

Saved the script as an application and tried to move a single file from Review Images to One - works just fine