Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 24, 2012, 02: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, 02:34 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Post your code.
chown33 is offline   0 Reply With Quote
Old Oct 24, 2012, 02: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, 07:22 PM   #4
sswany
Thread Starter
macrumors newbie
 
Join Date: Aug 2005
Anyone ?
sswany is offline   0 Reply With Quote
Old Oct 30, 2012, 07: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

Similar Threads
thread Thread Starter Forum Replies Last Post
Applescript moving files issue Liquid80 Mac Programming 2 Oct 3, 2013 12:29 AM
One last different AppleScript issue ring Mac Programming 3 Aug 7, 2013 10:20 PM
Resolved: [Applescript] Security Framework issue dezzeus Mac Programming 1 Mar 12, 2013 02:37 PM
WD Internal 3.5-inch Caviar Green HDDs - 32MB cache vs 64MB cache ToTo Man Buying Tips and Advice 3 Sep 14, 2012 01:39 PM
Weird G4 MDD Cache Issue!? adcx64 PowerPC Macs 4 Aug 5, 2012 04:30 PM

Forum Jump

All times are GMT -5. The time now is 05:58 PM.

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

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