I’ve got a script I’m working on to open each TIFF file in a folder, resize them according to my specs, save to new folder as TIFF, resize again according to different specs, save to same new folder but this time as a JPEG file and add “_sv” to the filename. I was able to get it work fine until I added the suffix part in and now the script fails when it tries to save the JPEG file.
I will also be adding to this script once I have this part fixed, as I need to make 2 more JPEG derivatives with different sizing specs and suffixes.
Any help would be appreciated.
on run
tell application "Finder"
set sourcePath to choose folder with prompt "Please select SOURCE folder:"
set savePath to choose folder with prompt "Please select DESTINATION folder:"
set fileList to (files of entire contents of sourcePath) as alias list
end tell
repeat until fileList = {}
set FilePath to item 1 of fileList as alias
tell application "Adobe Photoshop CS3"
open FilePath
set docHeight to height of document 1
set docWidth to width of document 1
set thisDoc to current document
tell thisDoc
(*
This section determines whether it is vertical or horizontal image and saves it as the Master TIFF at 3200 pixels and 300 dpi
*)
if docWidth is greater than docHeight then
resize image width 3200 as pixels resolution 300 resample method bicubic
else
resize image height 3200 as pixels resolution 300 resample method bicubic
end if
end tell
save document 1 in savePath as TIFF with options {class:TIFF save options, image compression:none} appending lowercase extension
(*
This section resizes the file to 3000 pixels and 300 dpi and saves as sv derivative jpeg
*)
set docHeight to height of document 1
set docWidth to width of document 1
set thisDoc to current document
tell thisDoc
if docWidth is greater than docHeight then
resize image width 3000 as pixels resolution 300 resample method bicubic
else
resize image height 3000 as pixels resolution 300 resample method bicubic
end if
end tell
set FilenameFull to (name of current document as text)
set Filename to first text item of FilenameFull
tell current document to save in (savePath & Filename & "_sv" & ".jpg") as JPEG with options {class:JPEG save options, embed color profile:true, format options:progressive, quality:8, scans:3} with copying
close document 1
end tell
set fileList to rest of fileList
end repeat
end run
Hi,
the problems are double referencing (tell theDoc and something of document 1)
and the specification of the destination path.
savePath is an alias, therfore you have to coerce it to a string path to append the name.
A third problem is the generation of the filename. AppleScripts text item delimiters are set to “” by default,
so your script takes always the first character of the name (first text item)
Try this, it uses a handler for the resize part
tell application "Finder"
set sourcePath to choose folder with prompt "Please select SOURCE folder:"
set savePath to choose folder with prompt "Please select DESTINATION folder:"
set fileList to (files of entire contents of sourcePath) as alias list
end tell
activate application "Adobe Photoshop CS3"
repeat with FilePath in fileList
set {name:Filename, name extension:Ex} to info for FilePath
if Ex is not missing value then set Filename to text 1 thru ((count Filename) - (count Ex) - 1) of Filename
tell application "Adobe Photoshop CS3"
open FilePath
set theDoc to my resizeDocument(document 1, 3200)
save theDoc in savePath as TIFF with options {class:TIFF save options, image compression:none} appending lowercase extension
set theDoc to my resizeDocument(document 1, 3000)
save theDoc in file ((savePath as text) & Filename & "_sv" & ".jpg") as JPEG with options {class:JPEG save options, embed color profile:true, format options:progressive, quality:8, scans:3} with copying
close document 1 saving no
end tell
end repeat
on resizeDocument(doc, theSize)
tell application "Adobe Photoshop CS3"
tell doc
if width is greater than height then
resize image width theSize as pixels resolution 300 resample method bicubic
else
resize image height theSize as pixels resolution 300 resample method bicubic
end if
end tell
return doc
end tell
end resizeDocument
Thanks Stefan. It worked beautifully.
Maybe I spoke too soon.
The script runs perfectly within Script Editor but when I save it as an Application and then run it by double clicking the app icon, the script runs but it changes the pixel size of every image to 1 x1 instead of using the specs that are in the script.
Could it possibly be from the “document 1” reference? It doesn’t seem likely though.
Any ideas?
You are setting the variable theDoc to the result of your function resizeDocument
set theDoc to my resizeDocument(document 1, 3200)
Then your function returns “doc” which is document 1 so when you come back, theDoc is “1”
on resizeDocument(doc, theSize)
tell application "Adobe Photoshop CS3"
tell doc
if width is greater than height then
resize image width theSize as pixels resolution 300 resample method bicubic
else
resize image height theSize as pixels resolution 300 resample method bicubic
end if
end tell
return doc
end tell
end resizeDocument
You are telling PhotoShop to save “1” (not any document) to the file path which it apparently interprets as save a 1 x 1 pixel document to the file path.
Seems to me that you are creating a subroutine as opposed to a function (i.e. no return value is needed):
tell application "Finder"
set sourcePath to choose folder with prompt "Please select SOURCE folder:"
set savePath to choose folder with prompt "Please select DESTINATION folder:"
set fileList to (files of entire contents of sourcePath) as alias list
end tell
activate application "Adobe Photoshop CS3"
repeat with FilePath in fileList
set {name:Filename, name extension:Ex} to info for FilePath
if Ex is not missing value then set Filename to text 1 thru ((count Filename) - (count Ex) - 1) of Filename
tell application "Adobe Photoshop CS3"
open FilePath
my resizeDocument(document 1, 3200)
save document 1 in savePath as TIFF with options {class:TIFF save options, image compression:none} appending lowercase extension
my resizeDocument(document 1, 3000)
save document 1in file ((savePath as text) & Filename & "_sv" & ".jpg") as JPEG with options {class:JPEG save options, embed color profile:true, format options:progressive, quality:8, scans:3} with copying
close document 1 saving no
end tell
end repeat
on resizeDocument(doc, theSize)
tell application "Adobe Photoshop CS3"
tell doc
if width is greater than height then
resize image width theSize as pixels resolution 300 resample method bicubic
else
resize image height theSize as pixels resolution 300 resample method bicubic
end if
end tell
end tell
end resizeDocument