Hello everyone,
I’m trying to create a Folder Action script so that I can designate one folder to be the recipient of any images I wish to resize. By creating a Folder Action script I can designate any folder I want as I “resize folder” and have multiple “resize folders” for various image items (including different sized items). I’ve worked with Applescript before, but I’m hardly one to make it do crazy hula dance tricks.
I’ve been able to locate two separate scripts (although they do different things) and I want to combine the two scripts to give me what I want.
- The first script resizes image files nicely and
 - The second script is a script which actually creates a folder and files away the end-product into the folder.
 
The first script does what I want, but leaves the image in the original folder. The second script is the “zip script” from Apple’s website, but it has a nice feature that creates a “Done” folder inside of the designated folder where it files away the completed zip file. I want to use this feature of the script to make the resizing script file away the resized images into a “Done” folder.
I’ve made attempts to combine the two scripts and I’m facing frustration.
Here are the separate scripts:
Resize script:
-- save in Script Editor as Application
-- drag files to its icon in Finder
on open some_items
	repeat with this_item in some_items
		try
			rescale_and_save(this_item)
		end try
	end repeat
end open
to rescale_and_save(this_item)
	tell application "Image Events"
		launch
		set the target_width to 144
		-- open the image file
		set this_image to open this_item
		
		set typ to this_image's file type
		
		copy dimensions of this_image to {current_width, current_height}
		if current_width is greater than current_height then
			scale this_image to size target_width
		else
			-- figure out new height
			-- y2 = (y1 * x2) / x1
			set the new_height to (current_height * target_width) / current_width
			scale this_image to size new_height
		end if
		
		tell application "Finder" to set new_item to ¬
			(container of this_item as string) & "scaled." & (name of this_item)
		save this_image in new_item as typ
	end tell
end rescale_and_save
ZIP script:
on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "Done" of this_folder) then
			make new folder at this_folder with properties {name:"Done"}
		end if
		set the destination_folder to folder "Done" of this_folder as alias
		set the destination_directory to POSIX path of the destination_folder
	end tell
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		if this_item is not the destination_folder and the name extension of the item_info is not in {"zip", "sit"} then
			set the item_path to the quoted form of the POSIX path of this_item
			set the destination_path to the quoted form of (destination_directory & (name of the item_info) & ".zip")
			do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & item_path & " " & destination_path)
		end if
	end repeat
end adding folder items to
Now here’s my attempt at combining them:
-- save in Script Editor as Application
-- drag files to its icon in Finder
on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "Done" of this_folder) then
			make new folder at this_folder with properties {name:"Done"}
		end if
		set the destination_folder to folder "Done" of this_folder as alias
		set the destination_directory to POSIX path of the destination_folder
	end tell
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		set the item_path to the quoted form of the POSIX path of this_item
		set the destination_path to the quoted form of (destination_directory & (name of the item_info))
		try
			tell application "Image Events"
				launch
				set the target_width to 144
				-- open the image file
				set this_image to open this_item
				
				set typ to this_image's file type
				
				copy dimensions of this_image to {current_width, current_height}
				if current_width is greater than current_height then
					scale this_image to size target_width
				else
					-- figure out new height
					-- y2 = (y1 * x2) / x1
					set the new_height to (current_height * target_width) / current_width
					scale this_image to size new_height
				end if
				
				tell application "Finder" to set new_item to ¬
					(container of this_item as string) & "scaled." & (name of this_item)
				save this_image in new_item as typ
				
			end tell
		end try
	end repeat
end adding folder items to
My script is incomplete because I get stuck on the part on where to designate that the “this_image” item be saved to the “destination_folder”.
If someone can point out my error (or point me in the direction of a better script!) I will greatly appreciate it.
Thanks a bunch.