New to Apple Script

I’m looking for a script that will resize jpeg images to 640x480 or 480x640(depending upon whether or nt the original image is a portrait or a landscape). I imagine a conditional statement will be involved to determine if the original image is landscape or portrait. Since some of the images wont scale exactly to 640x480 or to 480x640, due to contrain proportions. If the script could dictate imputing the 640 dimension into the width or height field depending upon if the image is landscape or portrait.
ie. original image is 3008px x 1960px (landscape) scaled down by imputing 640 width with constrained proportions the final image is 640x417.
ie. original image is 1960px x 3008px (portrait) scaled down by imputing 640 height with constrained proportions the final image is 417x640.
also, if the script could dictate saving the image in high quality jpeg format.
If someone could help me with this script I would be very very thankful!
I tried searching the forums and adapting some of the scripts to my needs but I have had no success yet.
Thank you,
Josh:)

The application i’m using is Photoshop 7.0 on osx.

This would also be intended for a batch process. :stuck_out_tongue:

ttweak:

Probably the simplest solution would be to create two separate actions in Photoshop; one for the landscape images and one for the portrait images. An Applescript could then easily be written to call whichever script was necessary depending on the image dimensions.

If you do not know how to create Photoshop actions, your only other choice would be to create a script using Image Events; also not difficult. For any script using Image Events, you need to be running OSX 10.4.x; it does not work well in 10.3.x. Which OSX are you using? I don’t know if the saving function of Image Events is similar to the high quality JPG saving function of Photoshop, however.

I (and many others here) can help you with scripting; but to create actions in Photoshop, you need to use their built in help functions, or get a book.

Let us know how you would like to proceed.

casdvm

I wrote a script that does what you need. I am in OS 10.3.9 in PhotoShop CS2 so this might not work in PhotoShop 7 without some tweaking. It should give you the basic idea even if you have to tweak it to work in 7. The main thing will be to copy the name of your Photoshop application (I assume it will be “Adobe Photoshop 7” or something close to that) and put that in where I have “Adobe Photoshop CS2”. Other than that, I am not sure what parts will or won’t work in version 7.

I set this up to work with any file format, not just JPEGs. It takes the extension off the file name. Copy this text into script editor and save it as an Application. You can then drag and drop a file or a folder full of files on the script icon. It saves the resulting files into a folder on your desktop called “JPEG_OUT”.

Good luck!

-- This droplet processes both files or folders of files dropped onto the applet
on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false) then
			my process_item(this_item)
		end if
	end repeat
	tell application "Finder"
		activate
	end tell
	beep 2
end open

-- this sub-routine processes folders
on process_folder(this_folder)
	set these_items to list folder this_folder without invisibles
	repeat with i from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item i of these_items))
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false) then
			my process_item(this_item)
		end if
	end repeat
end process_folder

on process_item(this_item)
	set PathToDesktop to path to the desktop as text
	tell application "Finder"
		activate
		if exists folder "JPEG_OUT" then
		else
			make new folder at desktop with properties {name:"JPEG_OUT"}
		end if
	end tell
	
	tell application "Adobe Photoshop CS2"
		activate
		delay 2
		set ruler units of settings to pixel units
		open this_item
		set AppleScript's text item delimiters to {":"}
		set TempFileName to last text item of (this_item as string)
		set AppleScript's text item delimiters to {"."}
		set FinalFileName to first text item of (TempFileName as string)
		if width of current document is greater than the height of current document then
			resize image current document width 640 resample method bicubic
		else
			resize image current document height 640 resample method bicubic
		end if
		save current document in file (PathToDesktop & ":JPEG_OUT:" & FinalFileName & ".jpg") as JPEG with options {class:JPEG save options, embed color profile:false, format options:standard, quality:12} without copying
		close current document saving no
	end tell
	
end process_item

Model: Mac G5
Operating System: Mac OS X (10.3.9)

Thank you so much for your generous gestures, I really appreciate your input on how to solve this problem.
I am running on os x 10.3.8 photoshop 7.0
I tried this script that you posted matt and changed the variable of photoshop cs to photoshop 7.0.
When I tried to save it as an application i got this error…

tell application “Adobe Photoshop 7.0”
activate
delay 2
set ruler units of settings to pixel units
open this_item
set AppleScript’s text item delimiters to {“:”}
set TempFileName to last text item of (this_item as string)
//(this line was noted and “text item” was highlighted with following message on next line.) set TempFileName to last text item of (this_item as string)
!!syntax error!! “Expected class name but found property.”

Thank you guys again!
The only thing I can think of at the moment to offer you guys is plenty of info on where and how to download live music show from famous jam bands of many styles.
-your friend
~Josh :wink:

I am sure that the errors are coming from the fact that you are in version 7 and I am in 9. Some of the syntax will be different. I am afraid I don’t have version 7 so I don’t have the answer for you. Maybe someone else out there does??

Anyone?

Well I guess most of you have upgraded above photoshop 7.0 a long time ago heh, are you guys aware of any other forums that might have people involved with Applescript and Photoshop 7.0?
-Hope you all have a Awesome 4 day weekend if thats the case, Happy Holidays.
~Josh