I’m hoping someone can help me clean up this code. I’m fairly new to AppleScript & am trying to call a subroutine. I need the code to look in a chosen folder (x), find all tifs in the subfolders of x, and process those tifs in Photoshop. Below is the code. Any help would be appreciated.
--Setting the variables
set inputFolder to (choose folder with prompt "Where's the input folder?")
set silosFolder to choose folder with prompt "Where's the silos folder?"
set filesForTrashFolder to choose folder with prompt "Where's the trash folder?"
--Move partials & files with "s" in the name to the "Silos" folder
tell application "Finder"
move (files of inputFolder whose name contains "partial") to silosFolder
move (files of inputFolder whose name contains "s") to silosFolder
end tell
--Put the remaining files in a list for running in Photoshop
processFolder(inputFolder)
tell application "Finder"
set filesList to (files of inputFolder whose name ends with "tif")
end tell
--Move the original tiffs to the "Ready for Trash" folder.
tell application "Finder"
move (files of inputFolder whose name ends with "tif") to filesForTrashFolder
end tell
--here are the subroutines
on processFile(fileRef)
--process a Finder file reference fileRef : Finder reference
tell application "Finder"
set theFile to aFile as alias
set theFileName to name of theFile
end tell
tell application "Adobe Photoshop CS2"
set display dialogs to never
open theFile
save current document in file (aFile as string) as Photoshop EPS with options {class:EPS save options, embed color profile:false, encoding:maximum quality JPEG, preview type:eight bit TIFF} appending lowercase extension
close current document saving no
end tell
end processFile
on processFolder(thisFolder)
--traverse a folder tree, calling processFile for each file found thisFolder : alias or Finder reference
tell application "Finder"
set filesList to every file of thisFolder
set foldersList to every folder of thisFolder
end tell
repeat with fileRef in filesList
processFile(fileRef)
end repeat
repeat with folderRef in foldersList
processFolder(folderRef)
end repeat
return
end processFolder
Are you having any specific problems?
Where does ˜aFile’ come from?
This may work better, unless the input folder is very large (then ˜entire contents’ will be quite slow):
set inputFolder to choose folder with prompt "Where's the input folder?"
set silosFolder to choose folder with prompt "Where's the silos folder?"
set trashFolder to choose folder with prompt "Where's the trash folder?"
tell application "Finder"
move (files of inputFolder whose name contains "partial" or name contains "s") to silosFolder
set fileList to (files of entire contents of inputFolder) as alias list
end tell
repeat with thisItem in fileList
try
set thisName to name of (info for thisItem without size)
tell application "Adobe Photoshop CS2"
launch
set display dialogs to never
open theFile
save current document in file (thisItem as Unicode text) as Photoshop EPS with options {class:EPS save options, embed color profile:false, encoding:maximum quality JPEG, preview type:eight bit TIFF} appending lowercase extension
close current document saving no
end tell
on error errMsg number errNum
display dialog "Error " & errNum & ":" & return & return & errMsg buttons {"Cancel", "Skip"} default button 1 with icon caution
end try
end repeat
tell application "Finder" to move (files of inputFolder whose name extension is "tif") to trashFolder
Note that I haven’t tested this yet.
Thanks for your help. That does seem to get me further. I am still receiving an error, however:
Error 8800: General Photoshop error occurred. -The object “current document” is not currently available. (Cancel) (Skip)
It seems as if it is not opening the Pshop files…
?
I just forgot to change the variable from ˜theFile’ to ˜thisItem’:
tell application "Adobe Photoshop CS2"
launch
set display dialogs to never
open thisItem -- change this line
Thanks for all of your help, Bruce.
I’m still getting the same 8800 error, however. Here’s the latest script. Any help is appreciated.
set inputFolder to choose folder with prompt "Where's the input folder?"
set silosFolder to choose folder with prompt "Where's the silos folder?"
set trashFolder to choose folder with prompt "Where's the trash folder?"
tell application "Finder"
move (files of inputFolder whose name contains "partial" or name contains "s") to silosFolder
set fileList to (files of entire contents of inputFolder) as alias list
end tell
repeat with thisItem in fileList
try
set thisName to name of (info for thisItem without size)
tell application "Adobe Photoshop CS2"
launch
set display dialogs to never
open thisItem
save current document in file (thisItem as Unicode text) as Photoshop EPS with options {class:EPS save options, embed color profile:false, encoding:maximum quality JPEG, preview type:eight bit TIFF} appending lowercase extension
close current document saving no
end tell
on error errMsg number errNum
display dialog "Error " & errNum & ":" & return & return & errMsg buttons {"Cancel", "Skip"} default button 1 with icon caution
end try
end repeat
tell application "Finder" to move (files of inputFolder whose name extension is "tif") to trashFolder
I don’t have that version of Photoshop, so there’s not much I can try. I did think of a little change though.
set inputFolder to choose folder with prompt "Where's the input folder?"
set silosFolder to choose folder with prompt "Where's the silos folder?"
set trashFolder to choose folder with prompt "Where's the trash folder?"
tell application "Finder"
move (files of inputFolder whose name contains "partial" or name contains "s") to silosFolder
set fileList to (files of entire contents of inputFolder) as alias list
end tell
tell application "Adobe Photoshop CS2"
activate
set display dialogs to never
end tell
repeat with thisItem in fileList
try
set thisName to name of (info for thisItem without size)
tell application "Adobe Photoshop CS2"
open thisItem
save current document in file (thisItem as Unicode text) as Photoshop EPS with options {class:EPS save options, embed color profile:false, encoding:maximum quality JPEG, preview type:eight bit TIFF} appending lowercase extension
close current document saving no
end tell
on error errMsg number errNum
activate
display dialog "Error " & errNum & ":" & return & return & errMsg buttons {"Cancel", "Skip"} default button 1 with icon caution
end try
end repeat
quit application "Adobe Photoshop CS2"
tell application "Finder" to move (files of inputFolder whose name extension is "tif") to trashFolder
Getting close!
The great news is that Photoshop is now processing the files. I realized that my “clean-up” lines must also be part of the subroutine, since the files to be moved are also in subfolders of inputFolder. When I moved these lines into the subroutine, I get the errors below:
Error -1728: Can’t get {} whose name contains “partial” or name contains “s” (I press SKIP) THEN
Can’t get {} whose name extension = “jpg”.
my latest script- notice the variable name changes in
move (files of fileList whose name contains "partial" or name contains "s") to silosFolder AND
tell application "Finder" to move (files of fileList whose name extension is "jpg") to trashFolder
set inputFolder to choose folder with prompt "Where's the input folder?"
set silosFolder to choose folder with prompt "Where's the silos folder?"
set trashFolder to choose folder with prompt "Where's the trash folder?"
tell application "Finder"
set fileList to (files of entire contents of inputFolder) as alias list
end tell
tell application "Adobe Photoshop CS2"
activate
set display dialogs to never
end tell
repeat with thisItem in fileList
try
set thisName to name of (info for thisItem without size)
move (files of fileList whose name contains "partial" or name contains "s") to silosFolder
tell application "Adobe Photoshop CS2"
open thisItem
save current document in file (thisItem as Unicode text) as Photoshop EPS with options {class:EPS save options, embed color profile:false, encoding:maximum quality JPEG, preview type:eight bit TIFF} appending lowercase extension
close current document saving no
end tell
on error errMsg number errNum
activate
display dialog "Error " & errNum & ":" & return & return & errMsg buttons {"Cancel", "Skip"} default button 1 with icon caution
tell application "Finder" to move (files of fileList whose name extension is "jpg") to trashFolder
end try
end repeat