Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 24, 2012, 01:03 PM   #1
sswany
macrumors newbie
 
Join Date: Aug 2005
AppleScript cache issue?

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 is offline   0 Reply With Quote
Old Oct 24, 2012, 01:34 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Post your code.
chown33 is offline   0 Reply With Quote
Old Oct 24, 2012, 01:41 PM   #3
sswany
Thread Starter
macrumors newbie
 
Join Date: Aug 2005
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
sswany is offline   0 Reply With Quote
Old Oct 30, 2012, 06:22 PM   #4
sswany
Thread Starter
macrumors newbie
 
Join Date: Aug 2005
Anyone ?
sswany is offline   0 Reply With Quote
Old Oct 30, 2012, 06:54 PM   #5
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Tested your code on Leopard and Snow Leopard. Works fine here. No re-output of the same images from the first group.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC