Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sswany

macrumors newbie
Original poster
Aug 9, 2005
10
1
I have an AppleScript app that I'm using to resize bulk images and output 2 versions into a folder. That all seems to work, but it seems to be having a strange issue. If I drop a group of images the first time on it, it outputs them all just fine. If I drop another group of images on it, it will re-output the same images from the first group. Is there a cache somewhere that I'm not aware of? Not sure great with AppleScript, but hoping someone could help.

Thanks!
 

sswany

macrumors newbie
Original poster
Aug 9, 2005
10
1
Code:
-- save in Script Editor as Application
-- drag files to its icon in Finder

on open some_items
	tell application "Finder"
		if (exists folder "output") then
		else
			make new folder with properties {name:"output"}
		end if
	end tell
	
	repeat with this_item in some_items
		try
			onex(this_item)
			twox(this_item)
		end try
	end repeat
end open


to onex(this_item)
	tell application "Image Events"
		launch
		set the target_width to 648
		-- 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
		
		-- change file name
		set _filename to name of this_item
		set _extension to name extension of this_item
		if _extension is not "" then
			set _length to (count of _filename) - (count of _extension) - 1
			set _newname to text 1 thru _length of _filename
		end if
		
		tell application "Finder" to set new_item to ¬
			(folder "output" as string) & _newname & "." & _extension
		save this_image in new_item as typ
		
	end tell
end onex

to twox(this_item)
	tell application "Image Events"
		launch
		set the target_width to 1296
		-- 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
		
		-- change file name
		set _filename to name of this_item
		set _extension to name extension of this_item
		if _extension is not "" then
			set _length to (count of _filename) - (count of _extension) - 1
			set _newname to text 1 thru _length of _filename
		end if
		
		tell application "Finder" to set new_item to ¬
			(folder "output" as string) & _newname & "_2x." & _extension
		save this_image in new_item as typ
		
	end tell
end twox
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Tested your code on Leopard and Snow Leopard. Works fine here. No re-output of the same images from the first group.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.