Help, script not resizing effectively.
Mattmcquiff Apr 26, 2013 9:08 AMHere is my script.
I thought I this was working then on the next image it plays up.
having big issues with something I thought was so simple.
I have some sample files here.
If you download them and call the folder Brand_WK99_PSD
property type_list : {"8BPS"}
property extension_list : {"psd"}
script o
property theseNames : {}
end script
--empty log file
do shell script "echo 'Files not processed in Photoshop :' > ~/Desktop/LogPhotoshopError.txt"
set noError to true
set posixCS6Path to "/Applications/Adobe Photoshop CS6/Adobe Photoshop CS6.app"
tell application posixCS6Path to activate
--at the beginning of the script, ask whether to replace or skip existing files? to apply to all?
--use the result for the if file exists?
display dialog "Should I replace or skip exisiting files?" buttons {"Replace", "Skip (Faster)"} default button 2 with icon 1
set skipFiles to (button returned of the result) is "Skip (Faster)"
--Setup list of folders and process details of folders
set AFolder to (choose folder with prompt "Select Mikey Folder")
tell application "Finder"
set folderName to name of folder AFolder as text --<: is the folder name, no need to use text item delimiters -->":"
end tell
log folderName
set {oldTID, my text item delimiters} to {my text item delimiters, "_WK"}
set FolderEndName to last text item of folderName
set brandName to first text item of folderName
set my text item delimiters to "_PSD"
set weekNumber to first text item of FolderEndName
set my text item delimiters to oldTID
set theFolder to AFolder as string
--set up names to destination folders and create locally based on brand name and week number
set this_local_folder to "Images:"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
set localBrandFolder_PSD to my getFolderPath(brandName & "_WK" & weekNumber & "_PSD", localBrandFolder)
--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
-- its not boots it Mikey but uses boots
-- Mikey Folders --
set this_ftp_folder to "boots:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
set ftpBrandFolder_PNGs to my getFolderPath("PNG", ftpBrandFolder)
set ftpBrandFolder_JPGs to my getFolderPath("JPG", ftpBrandFolder)
set ftpBrandFolder_1500_PNG to my getFolderPath("HF_1500px", ftpBrandFolder_PNGs)
set ftpBrandFolder_960_PNG to my getFolderPath("960px", ftpBrandFolder_PNGs)
set ftpBrandFolder_480_PNG to my getFolderPath("480px", ftpBrandFolder_PNGs)
set ftpBrandFolder_215_PNG to my getFolderPath("215px", ftpBrandFolder_PNGs)
set ftpBrandFolder_110_PNG to my getFolderPath("110px", ftpBrandFolder_PNGs)
set ftpBrandFolder_1500_JPG to my getFolderPath("HF_1500px", ftpBrandFolder_JPGs)
set ftpBrandFolder_960_JPG to my getFolderPath("960px", ftpBrandFolder_JPGs)
set ftpBrandFolder_480_JPG to my getFolderPath("480px", ftpBrandFolder_JPGs)
set ftpBrandFolder_215_JPG to my getFolderPath("215px", ftpBrandFolder_JPGs)
set ftpBrandFolder_110_JPG to my getFolderPath("110px", ftpBrandFolder_JPGs)
try
tell application "Finder" to set o's theseNames to (name of files of alias theFolder whose file type is in the type_list or name extension is in the extension_list)
on error
set o's theseNames to {} -- no psd files or "8BPS"
end try
set numOfNames to (count o's theseNames)
repeat with j from 1 to numOfNames
set thefile to theFolder & (item j of o's theseNames)
-- Mikey Folder Photoshop Process W I T H P N G
set thisName to (item j of o's theseNames)
tell application "Finder"
set t_ext to name extension of file thefile
if t_ext is not "" then set thisName to text 1 thru -((count t_ext) + 2) of thisName
set b to exists file (localBrandFolder_PSD & thisName & ".psd")
end tell
if not b or (b and not skipFiles) then -- not exists file or file exists and "replace" (continue the rest of the script).
tell application "Adobe Photoshop CS6"
-- I remove the command activate, Photoshop stay in background
set ruler units of settings to pixel units
try
open (alias thefile) showing dialogs never
set origName to name of current document
set myOptions to {class:JPEG save options, quality:12}
set myPNGOptions to {class:PNG save options, interlaced:false}
set myPSDOptions to {class:Photoshop save options, embed color profile:true, save layers:true}
tell current document
if (quick mask mode) then delete channel ¬
"Quick Mask"
if (exists layer "Original Layer") then ¬
tell layer "Original Layer" to set name to "Original Image"
save in (localBrandFolder_PSD & origName) as Photoshop format with options myPSDOptions without copying
(delete layer "Original Image")
delete layer "BACKGROUND" of layer set "Dodge and Burn"
tell current layer to set name to "Main Image"
merge visible layers
resize image width 1500 resample method bicubic sharper
resize image resolution 300 resample method none
filter current layer using unsharp mask with options {amount:34, radius:1.0, threshold:0}
save in (ftpBrandFolder_1500_PNG & name) as PNG with options myPNGOptions without copying
flatten
save in (ftpBrandFolder_1500_JPG & name) as JPEG with options myOptions without copying
set current history state to history state 6
trim
end tell
set cWidth to width of current document
set cHeight to height of current document
set HeightIncrease to 1.1
set LargeLandH to 700
set LargeLandW to 960
set MediumLandH to 350
set MediumLandW to 480
set SmallLandH to 155
set SmallLandW to 215
(*set BI to (round ((dHeight / sHeight) * 10))
if BI is equal to "4" then
set HeightIncrease to 10
else if BI is equal to
set
log HeightIncrease*)
tell current document
tell application "Adobe Photoshop CS6"
set ruler units of settings to point units
end tell
resize image height LargeLandH
resize canvas height (LargeLandH * HeightIncrease) anchor position middle center
resize image height LargeLandH
resize canvas width (LargeLandW) anchor position middle center
tell application "Adobe Photoshop CS6"
set ruler units of settings to pixel units
end tell
resize image height LargeLandH resample method bicubic sharper
resize image resolution 300 resample method none
filter current layer using unsharp mask with options {amount:34, radius:1.0, threshold:0}
--add save to lowResFolder with same options
save in (ftpBrandFolder_960_PNG & name) as PNG with options myPNGOptions without copying
flatten
save in (ftpBrandFolder_960_JPG & name) as JPEG with options myOptions without copying
set current history state to history state 6
trim
tell application "Adobe Photoshop CS6"
set ruler units of settings to point units
end tell
resize image height MediumLandH
resize canvas height (MediumLandH * HeightIncrease) anchor position middle center
resize image height MediumLandH
resize canvas width (MediumLandW) anchor position middle center
tell application "Adobe Photoshop CS6"
set ruler units of settings to pixel units
end tell
resize image height MediumLandH resample method bicubic sharper
resize image resolution 300 resample method none
filter current layer using unsharp mask with options {amount:34, radius:1.0, threshold:0}
save in (ftpBrandFolder_480_PNG & name) as PNG with options myPNGOptions without copying
flatten
save in (ftpBrandFolder_480_JPG & name) as JPEG with options myOptions without copying
set current history state to history state 6
trim
tell application "Adobe Photoshop CS6"
set ruler units of settings to point units
end tell
resize image height SmallLandH
resize canvas height (SmallLandH * HeightIncrease) anchor position middle center
resize image height SmallLandH
resize canvas width (SmallLandW) anchor position middle center
tell application "Adobe Photoshop CS6"
set ruler units of settings to pixel units
end tell
resize image height SmallLandH resample method bicubic sharper
resize image resolution 300 resample method none
filter current layer using unsharp mask with options {amount:34, radius:1.0, threshold:0}
--add save to lowResFolder with same options
save in (ftpBrandFolder_215_PNG & name) as PNG with options myPNGOptions without copying
flatten
save in (ftpBrandFolder_215_JPG & name) as JPEG with options myOptions without copying
set current history state to history state 6
trim
if cWidth > cHeight then
resize image width 110
resize canvas height 110
else
resize image height 110
resize canvas width 110
end if
resize image resolution 300 resample method none
filter current layer using unsharp mask with options {amount:34, radius:1.0, threshold:0}
--add save to lowResFolder with same options
save in (ftpBrandFolder_110_PNG & name) as PNG with options myPNGOptions without copying
flatten
save in (ftpBrandFolder_110_JPG & name) as JPEG with options myOptions without copying
close saving no
end tell
on error
set noError to false
my myLogs(thefile) -- write path to log file in Desktop
try
close saving no --if exists, close current document
end try
end try
end tell
end if
end repeat
--End F R E E D O M W I T H P N G
--if not noError then do shell script "/usr/bin/open ~/Desktop/LogPhotoshopError.txt'"
on myLogs(t)
try
do shell script "echo " & (quoted form of t) & ">> ~/Desktop/LogPhotoshopError.txt'"
end try
end myLogs
on duplicateFile(tFile, foldersPath) -- tFile is an alias, foldersPath is a list of folder
tell application "Finder" to repeat with folderPath in foldersPath
with timeout of 200 seconds -- adjust it, error if the copy is longer that 200 seconds
duplicate tFile to folder folderPath with replacing
end timeout
end repeat
end duplicateFile
on getFolderPath(tName, folderPath)
tell application "Finder" to tell folder folderPath
if not (exists folder tName) then
return (make new folder at it with properties {name:tName}) as string
else
return (folder tName) as string
end if
end tell
end getFolderPath
