Resizing is much easier than duplicating.

I am attempting to duplicate a file to a new location using the below listed code. The idea is to perform a resizing on all .jpg photos and if the file is not a .jpg format, I want to simply copy (duplicate) the file to the same directory as the resized .jpg’s are being sent since the text files refer to the .jpg files and need to be kept together. In this case, the new directory is a sub directory of the original, but I would also like it to be generic enough to use any directory based on the Original_folder by adding or deleting to that directory. Since I am new to scripting and I am still not clear on variables, how they are handled and their properties, I have copied multiple snippets of code to accomplish the process and I have been unsuccessful in every single attempt which includes an alias of Original_folder and multiple other naming conventions. The code following the else command is my latest attempt and it, too, gives me an error (Finder got an error: Can’t make document file “10-email.txt” of folder “queue” of folder “Desktop” of folder “jake” of folder “Users” of startup disk into type integer.) Any suggestions?

tell application "Finder"
	--variable initialization
	set Original_folder to ":Users:Jake:Desktop:queue:" as alias
	set a_list to every file of folder Original_folder
	set the target_length to 640
	set the target_dimension to "Width"
	
	set i to 1
	repeat 20 times
		set this_file to (item i of a_list) as string
		set file_extension to the last word of this_file
		if the file_extension is "jpg" then
			try
                          -- A whole lot of stuff goes on here for the .jpg files
                        end try
                   set i to i +1
		else
			set new_folder to ("HD/Users/Jake/Desktop/queue/queue1/" as text)
			tell application "Finder"
				duplicate file (item i of a_list) to new_folder
				set i to i + 1
			end tell
		end if
	end repeat
end tell

Model: IMac G-5
AppleScript: 2.0.1
Browser: Firefox 3.0.4
Operating System: Mac OS X (10.5)

See if this works.


tell application "Finder"
	set a_list to every file of folder ((path to desktop) & "queue:" as string)
	set the target_length to 640
	set the target_dimension to "Width"
	
	repeat with i from 1 to length of a_list
		set this_file to item i of a_list as alias
		if name extension of this_file is "jpg" then
			try
				-- A whole lot of stuff goes on here for the .jpg files
			end try
		else
			duplicate (item i of a_list) to ((path to desktop) & "queue:queue1:" as string)
		end if
	end repeat
end tell

I like the code that eliminates the variables Original_folder and new_folder and while all the .jpg’s are modified and transferred the error message remains the same when the first .txt file is encountered.

Oops, I need to learn to read better. I FINALLY eliminated the “file” from my code in the duplicate command line and everything is now working. Thanks so much, Craig.

Where in this forum can I find a tutorial that explains variables and how the use of “as alias”, “as text”, “as Unicode text”, “as Folder” or the rest of the modifiers treat the variable? Better yet, is there a display file that lists them all?