PreFab...Player...Cool Uses...Photoshop...

Set Maximum Height

This script shows the power of AppleScript and Player together. It shrinks images above a certain height down to a specified maximum without affecting images that are within the acceptable range. (Clearly, just typing the maximum height wouldn't work, that would enlarge small images.) It also saves two different copies, at different resolutions and formats.
-- original script written by Anne Hastings (anneh@ento.csiro.au), June 1996 (for Player 1.1)
-- requires Jon's commands for extracting a value via the clipboard
-- edited by PreFab Software, Inc., distributed with permission

(*
1. flatten image
2. set maximum height to 960 (without increasing height of smaller images)
3. save as tiff to specific folder
4. set maximum height to 480
5. save as gif to same folder as tiff files
*)

set batchFolder to choose folder
-- set batchFolder to "disk:folder:"

set doneFolder to createDoneFolder(batchFolder)

tell application "Finder"
	-- "document file" excludes aliases, apps, control panels, etc.
	set listOfFiles to (get every document file of folder batchFolder whose file type is not "TIFF")
end tell

activatePhotoshop()

set firstFile to true
repeat with imageFile in listOfFiles
	if openImage(imageFile) then
		-- first flatten & create a TIFF
		flattenImage()
		setMaximumHeight(960) -- sets maximum height, leaving smaller values alone
		saveAsCompressedPCTIFFTo(doneFolder, firstFile)
		
		-- now create a GIF
		setMaximumHeight(480) -- sets maximum height, leaving smaller values alone
		indexedColor()
		saveAsGIFTo(doneFolder)
		
		closeImage()
		set firstFile to false
	end if
end repeat

activate me
display dialog "Done processing folder!"


-- ---------------------------------------- subroutines ---------------------------------------- 
on flattenImage()
	tell application "PreFab Player™"
		-- note: may need a wait of some sort here
		try
			do menu menu item "Show Layers" of submenu "Palettes" of menu "Window"
			yield time 60 -- give it time to update the screen
		on error
		end try
		set target window to "Layers"
		try
			do menu popup item "flatten image" of popup {200, 8} -- the options popup in the corner
		on error
			-- no problem if it is already flat
		end try
		set target window to 1
	end tell
end flattenImage

-- ---------------------------------------- 
on setMaximumHeight(H)
	-- requires Jon's commands for extracting the value via the clipboard
	tell application "PreFab Player™"
		do menu menu item "Image Size" of menu "Image" with repeat until successful
		type {tab, tab}
		set currentValue to my getValue()
		if currentValue > H then
			type (H as string)
		end if
		type enter -- accept dialog
	end tell
end setMaximumHeight

-- ---------------------------------------- 
on getValue()
	-- requires Jon's commands for extracting the value via the clipboard
	tell application "PreFab Player™"
		do menu menu item "Copy" of menu "Edit"
		yield time 10 -- make sure the clipboard gets updated in Photoshop
	end tell
	activate -- bring the script to the front to convert the clipboard
	tell application "PreFab Player™"
		yield time 10 -- make sure the clipboard gets updated in the script
	end tell
	
	-- the "minus 0" is a clever way to convert to integer or real, as appropriate
	set theValue to ((«event sysogclp» given «class rtyp»:string) - 0)
	
	tell application "Adobe Photoshop™ 3.0" to activate
	tell application "Finder"
		-- "hide others" to avoid some of the screen refresh:
		set visible of every process whose creator type is not "8BIM" to false
	end tell
	
	return theValue
end getValue

-- ---------------------------------------- 
on indexedColor()
	-- accept default settings
	-- note: may need a wait of some sort here
	tell application "PreFab Player™"
		if not enabled of (get info menu item "Indexed Color" of menu "Mode") then
			-- often can't go directly to Indexed Color; RGB is the most universal route
			if enabled of (get info menu item "RGB" of menu "Mode") then
				do menu menu item "RGB" of menu "Mode"
			else
				-- could be bitmap
				error "Can't switch from current mode to Indexed Color directly or via RGB."
			end if
		end if
		do menu menu item "Indexed Color" of menu "Mode"
		
		if name of (get info window 1) ≠ "Indexed Color" then
			-- no dialog: either it was already indexed color, or perhaps grayscale
			return true
		end if
		
		click button "OK"
	end tell
end indexedColor

-- ---------------------------------------- 
on saveAsCompressedPCTIFFTo(outputFolder, isFirstFile)
	tell application "PreFab Player™"
		set dialog folder to outputFolder
		do menu menu item "Save As" of menu "File" with repeat until successful
		
		-- the following lines shouldn't be required in the released version of Player 1.1
		click button "Cancel" -- had to cancel and do "Save as" again to get the path to folder to be accepted.
		do menu menu item "Save As" of menu "File"
		
		do menu popup item "TIFF" of popup "Format"
		type {right arrow, ".tif", enter}
		if exists button "Replace" then
			click button "Replace"
		end if
		if isFirstFile then -- save a little bit of time by skipping on subsequent files
			click radio button "IBM PC"
			set value of checkbox "LZW Compression" to 1
		end if
		click button "OK"
	end tell
end saveAsCompressedPCTIFFTo

-- ---------------------------------------- 
on saveAsGIFTo(outputFolder)
	-- GIF files must be grayscale or indexed color; SEE convertToGIF() & variations
	
	tell application "PreFab Player™"
		set dialog folder to outputFolder
		do menu menu item "Save As" of menu "File" with repeat until successful
		
		-- the following lines shouldn't be required in the released version of Player 1.1
		click button "Cancel" -- had to cancel and do "Save as" again to get the path to folder to be accepted.
		do menu menu item "Save As" of menu "File"
		
		do menu popup item "CompuServe GIF" of popup "Format"
		
		-- have to replace ".tif" or similar with ".gif"
		type {my getRootFilename(), ".gif", enter}
		if exists button "Replace" then
			click button "Replace"
		end if
	end tell
end saveAsGIFTo

-- ---------------------------------------- 
on getRootFilename()
	-- strip off the last extension (including the period)
	-- e.g. to replace ".TIFF" extension with ".PICT"
	
	tell application "PreFab Player™"
		set currentFilename to item text of (get info dialog item 10) -- 10 is the ID of the filename textbox
	end tell
	repeat with i from (count of currentFilename) to 1 by -1
		if character i of currentFilename is "." then
			return text 1 thru (i - 1) of currentFilename
		end if
	end repeat
	return currentFilename -- there wasn't an extension
end getRootFilename
-- ---------------------------------------- the end ---------------------------------------- 

| Top |


To CMYK TIFF, Omit .PICT| Prev | Home | Next |YCC for PhotoCD

Updated on 10/7/96 by Scott S. Lawton (ssl@prefab.com)

Copyright 1993-97, PreFab Software, Inc. All Rights Reserved.

This site built and maintained using Stage Three, a set of custom Frontier scripts.