Player
Cool Uses
Photoshop
-- Photoshop example by PreFab Software, Inc.
-- task suggested by a customer: sharpen, set dpi & export to YCC with Kodak plug-in
-- customer then uses Kodak BuiltIt software to create ImagePacks (5 resolutions) for "Portfolio CD"
-- it accepts the default values for Unsharp Mask; see other examples for setting them in the script
-- for Player 1.1b5, July 5, 1996 ... edited 7/31/96 & 9/25/96
-- to save disk space, overwrite the images instead of saving to a done folder
set theFolder to choose folder
-- or: set theFolder to "disk:folder:"
set replaceOriginal to true
set listOfFiles to getListOfFiles(theFolder)
activatePhotoshop()
repeat with theFile in listOfFiles
if openImage(theFile) then -- openImage returns false if the file didn't get opened into Photoshop
unsharpMask() -- accept default values
imageResolution(300) -- pixels per inch (or cm, whichever is set)
mode("CMYK Color")
-- 9/25: keep trying if there's a spurious error
repeat while not exportToYCC(replaceOriginal) -- "true" to replace original, or specify path to the done folder
-- it did NOT export, but we should save changes
saveImage()
-- let it try again, the error will go away eventually
end repeat
closeImage()
end if
end repeat
activate me
display dialog "Done processing folder!"
-- ------------------------------ Image processing subroutines ------------------------------
on unsharpMask()
tell application "PreFab Playerª"
try -- after the first image, the filter is the first item... selecting from there skips the dialog
do menu menu item "Unsharp Mask" of menu "Filter" -- DON'T repeat until successful
on error
do menu menu item "Unsharp Mask" of submenu "Sharpen" of menu "Filter" with repeat until successful
-- assume the default settings are ok
type enter
end try
end tell
end unsharpMask
-- ----------------------------------------
on imageResolution(pixelsPer)
tell application "PreFab Playerª"
do menu menu item "Image Size" of menu "Image" with repeat until successful
-- default popup setting is "pixels per inch"
type {pixelsPer, enter}
end tell
end imageResolution
-- ----------------------------------------
on mode(whichMode)
tell application "PreFab Playerª"
do menu menu item whichMode of menu "Mode" with repeat until successful
end tell
end mode
-- ----------------------------------------
on exportToYCC(whichFolder)
-- originally written for a "done" folder; can also just pass "true" for replace
tell application "PreFab Playerª"
if class of whichFolder boolean then -- true [or even false] means to overwrite, otherwise point to done folder
set dialog folder to whichFolder
end if
do menu menu item "Kodak CMS Ycc TIFF Export" of submenu "Export" of menu "File" with repeat until successful
-- it may take a few seconds for the dialog to appear
repeat while not (exists button "Save")
yield time 60
end repeat
set forced yield to true -- 7/31/96: the replace button doesn't get clicked on the first image
-- -- beep doesn't work on his machine (!) so I can't accurately diagnose the problem, this fix is a guess
click button "Save"
if exists dialog item 2 then
if kind of (get info dialog item 2) = "Static Text" then
-- error message such as "Both source & destination Precision Transforms are required."
-- Player 1.1b5 cannot get the actual text
click button "OK"
click button "Cancel"
-- leave the image; the calling script can decide whether to close
return false -- quit early
end if
end if
if exists button "Replace" then
click button "Replace"
end if
-- occasionally get a spurious Photoshop error "not enough memory"
-- I haven't tested to see if this code catches it (since I haven't seen the error)
if exists button "OK" then
click button "OK"
set forced yield to false
return false -- 9/25/96
end if
set forced yield to false
return true
end tell
end exportToYCC
-- ------------------------------ General subroutines ------------------------------
on activatePhotoshop()
tell application "Adobe Photoshopª 3.0" to activate
tell application "PreFab Playerª"
yield time 60 -- give image & palettes time to update
end tell
try
app menu "Hide Others" -- avoids some of the screen refresh
-- there's probably a Scriptable Finder solution too...
on error
-- don't worry if app menu isn't installed
end try
end activatePhotoshop
-- ----------------------------------------
on createDoneFolder(whichFolder)
tell application "Finder"
set doneName to "Done"
set parentFolder to (container of whichFolder)
repeat while exists folder doneName of parentFolder
set doneName to doneName & "!"
end repeat
set outputFolder to make new folder at (parentFolder) with properties {name:doneName}
set outputFolder to (outputFolder as string) -- used for "set dialog folder" which doesn't accept a Finder reference
-- returned below
end tell
return outputFolder
end createDoneFolder
-- ----------------------------------------
on openImage(whichFile)
-- telling Photoshop to open works on most machines but not all
tell application "Finder"
-- it won't be an alias if the list only asked for "document files", but just in case
if class of whichFile is alias file then
return false
else
open whichFile
-- if double-clicking on the file won't open it, you may need to add:
-- with application "Adobe Photoshopª 3.0" of folder "whatever" of disk "whatever"
-- I don't know a portable way of specifing a reference to Photoshop
tell application "PreFab Playerª"
yield time 60 -- give the image or file time to open
if exists dialog item 5 then
if kind of (get info dialog item 5) = "Static Text" then
-- error message such as "Could not open __ because the TIFF file uses an unsupported color space."
-- (I think the image was exported to the Kodak YCC space.)
-- FYI, other items in the dialog: #1: "OK" button, #2: icon, #4: User Item (numerical error)
click button "OK"
return false
end if
end if
end tell
-- return false if opening the file didn't bring Photoshop to the front
return (frontmost of process ("Adobe Photoshopª 3.0"))
end if
end tell
end openImage
-- ----------------------------------------
on waitForMenubar()
-- one reason this routine is important: sometimes get info *can* do its thing while a progress window is up
-- but if a menu item isn't enabled, it will also think it's not checked
-- independent of whether it's "really" checked once enabled
tell application "PreFab Playerª"
set ready to false
repeat while not ready
try
-- remember: menu 1 is the Apple menu
set ready to enabled of (get info menu item 1 of menu 2) -- usually File/New but shouldn't matter
on error
yield time 60
end try
end repeat
end tell
end waitForMenubar
-- ----------------------------------------
on saveImage()
tell application "PreFab Playerª"
do menu menu item "Save" of menu "File"
end tell
end saveImage
-- ----------------------------------------
on closeImage()
-- 9/25/96: changed it to save, although we think it will never happen given the new repeat loop
-- also changed to "if exists" instead of try
waitForMenubar() -- added 7/31/96: not sure why "repeat until successful" gives an error
tell application "PreFab Playerª"
do menu menu item "Close" of menu "File" with repeat until successful
if exists button "Save" then
click button "Save" -- may have exported the changed version
yield time 60 -- this may not be enough for a long save process
end if
end tell
end closeImage
-- ----------------------------------------
on getListOfFiles(whichFolder)
tell application "Finder"
-- "document file" excludes aliases, apps, control panels, etc.
set tempList to (get every document file of folder whichFolder)
-- or: set listOfFiles to document files in folder theFolder
-- could add something like: whose file type is not "GIFf"
end tell
if tempList is {} then
-- "matching" only makes sense with a "whose" clause above
error "There are no matching files in that folder."
end if
return tempList
end getListOfFiles
-- ---------------------------------------- the end ----------------------------------------
Copyright 1993-97, PreFab Software, Inc. All Rights Reserved.
This site built and maintained using Stage Three, a set of custom Frontier scripts.