The script should create a folder structure, then size and save images as jpeg in their perspective folders.
tell application "Finder"
activate
try
make new folder with properties {name:"Web Images"} at desktop
on error
display dialog "There is already a folder named “Web Images” 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" of desktop
on error
display dialog "There is already a folder named " & folder_name & " in the folder “Web Images” 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
set these_files to choose file without invisibles
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 "Image Events"
launch
set the new_name to my add_extension(these_files, "jpg")
if (exists file new_name of folder folder_name of folder "Web Images" of folder desktop) then
error "A file named \"" & new_name & "\" already exists."
end if
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 new_name of folder folder_name of folder "Web Images" of folder desktop) 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
Any help would be appreciated.
Thanks!