Simon, this is the rearranged version. Reminds this 64 year old of the days when I used to program Hypercard (you young whippersnapper have heard of Hypercard haven't you? Everything could have an interactive script behind it, sort of subroutines on steroids. Badly miss it.)
-- Photoshop Action Script
-- by Brian Christmas
-- August 2012
global ptdpp
global ptdpif
global ptdpsf
global fileToLog
global file_to_save
global file_Name2
global file_Extension
property PhotoshopFiles : {}
on adding folder items to this_folder after receiving tempPhotoshopFiles -- we don't really want these, in case there's more in the folder that did not trigger the Folder Action, a common occurrance
try
set ptd to path to desktop as text
set ptdpp to this_folder as text
set ptdpif to ptd & "Processed Images Folder" as text
set ptdpsf to ptd & "Processed Stored Folder" as text
set fileToLog to (ptdpif) & ":Photoshop_Batch_Errors_Log.txt" as text
my makeNewFolders()
set SayThis to " files"
if (count of PhotoshopFiles) = 1 then set SayThis to " file"
say (count of PhotoshopFiles) & SayThis as text
tell application "Adobe Photoshop CS6"
repeat with this_File in PhotoshopFiles
my resetFirstFolder(this_File)
open this_File
try
do action "Wood Frame - 50 pixel" from "Default Actions" without notifiers enabled and display dialogs -- < this particular action brings up a dialog box which can't be addressed with Applescript
save current document in file file_to_save with copying -- < set to 'without copying' if original files not required
on error errmsg
display dialog errmsg -- < write to ":Photoshop_Batch_Errors_Log.txt" here
end try
try
close document 1 saving no
end try
my resetSecondFolder(this_File)
end repeat
end tell
on error errmsg
display dialog errmsg
end try
end adding folder items to
on makeNewFolders()
tell application "Finder"
if not (exists folder ptdpif) then
make new folder at folder ptd with properties {name:"Processed Images Folder"}
end if
if not (exists folder ptdpsf) then
make new folder at folder ptd with properties {name:"Processed Stored Folder"}
end if
if not (exists file fileToLog) then
make new file at folder ptdpif with properties {name:"Photoshop_Batch_Errors_Log.txt"}
end if
set PhotoshopFiles to every file of folder ptdpp as alias list -- These are the files we want, every one in the folder
end tell
end makeNewFolders
on resetFirstFolder(this_File) -- ALL saved as default .psd files
tell application "Finder"
set file_Name to name of this_File
set file_Extension to "psd" --default Save name extension of this_File, will require altering if default is reset eg to jpeg
set file_Name2 to characters 1 through -((count of file_Extension) + 2) of file_Name as text
set file_to_save to (ptdpif & ":" & file_Name2 & "." & file_Extension as text)
set x to 1
repeat
if not (exists file file_to_save) then exit repeat
set file_to_save to (ptdpif & ":" & file_Name2 & " " & x & "." & file_Extension as text)
set x to x + 1
end repeat
end tell
end resetFirstFolder
on resetSecondFolder(this_File) -- ALL saved in original name extensions
tell application "Finder"
set file_to_store to (ptdpsf & ":" & file_Name2 & "." & file_Extension as text)
set file_Extension to name extension of this_File
set x to 1
repeat
if not (exists file file_to_store) then exit repeat
set file_to_rename to (ptdpsf & ":" & file_Name2 & " " & x & "." & file_Extension as text)
if not (exists file file_to_rename) then
set name of file file_to_store to (file_Name2 & " " & x & "." & file_Extension as text)
exit repeat
end if
set x to x + 1
end repeat
try
move this_File to folder ptdpsf
on error
try
move this_File to folder ptdpsf with replacing
on error errmsg
display dialog errmsg -- < write to ":Photoshop_Batch_Errors_Log.txt" here
end try
end try
end tell
end resetSecondFolder