This should work.
property theFolder : "Web Images"
global PathToDesktop
set PathToDesktop to path to desktop
tell application "Finder"
activate
try
make new folder with properties {name:theFolder} at desktop
on error
display dialog "There is already a folder named “" & theFolder & "” on your desktop. Would it be okay to use it?"
end try
set folder_names to {"Large", "Medium", "Small", "Icon"}
repeat with folder_name in folder_names
try
make new folder with properties {name:folder_name} at folder "Web Images"
on error
display dialog "There is already a folder named " & folder_name & " in the folder “" & theFolder & "” on your desktop. Would it be okay to use it? All images with the same name will be replaced."
end try
end repeat
end tell
tell application "Finder"
activate
set these_files to choose file without invisibles
end tell
set the target_lengths to {400, 250, 120, 79}
repeat with target_length in target_lengths
set folder_names to {"Large", "Medium", "Small", "Icon"}
repeat with folder_name in folder_names
set jpeg_sizes to {"_Large", "_Medium", "_Small", "_Icon"}
repeat with jpeg_size in jpeg_sizes
try
tell application "Finder"
set the new_name to my add_extension(these_files, "jpg")
if (exists file new_name of folder folder_name of folder theFolder) then
display dialog "A file named \"" & new_name & "\" already exists."
end if
set thePath to (PathToDesktop & theFolder & ":" & folder_name & ":" & new_name) as text
end tell
tell application "Image Events"
launch
set this_image to open these_files
copy dimensions of this_image to {w, h}
scale this_image to size target_length
set new_image to save this_image as JPEG in file thePath with icon
close this_image
end tell
on error error_message
display dialog error_message
end try
end repeat
end repeat
end repeat
on add_extension(these_files, new_extension)
set this_info to the info for these_files
set this_name to the name of this_info
set this_extension to the name extension of this_info
set jpeg_sizes to {"_Large", "_Medium", "_Small", "_Icon"}
repeat with jpeg_size in jpeg_sizes
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & jpeg_size & "." & the new_extension)
end repeat
end add_extension