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)