I have a script that that converts pdfs to cmyk, renames the files, adds footers and trim marks, then sorts them to folders according to there size. During the renaming process the last word of the file name contains the document size, ei: “_4ft.pdf”.
Then last part of the script creates folders and does the sorting. All works well.
The problem comes up if I add more files to the parent folder and rerun the script. When it gets to the sorting process,
I get an error -1728 "Finder got an error: Can’t get every document file of alias "PitBat2:Users:PitBat2:Public:Live Jobs:Speedway Job# 1863B:" whose kind ≠"Folder" and name contains "_24In.pdf".
Like I said this only happens if I add files to the parent folder after the script has created the sort folders. If I move the sort folders created by the script out of the parent folder, then all is well.
If anyone is working with Acrobat and PitStop, I will be glad to share what I have learned about GUI scripting this app and plugin.
thanks much
Michael Blaylock
tell application “Finder”
activate
try
set new_folder2ft to (make new folder at JobFolderpath with properties {name:JobNumber & “_2Ft”})
set new_folder3ft to (make new folder at JobFolderpath with properties {name:JobNumber & “_3Ft”})
set new_folder4ft to (make new folder at JobFolderpath with properties {name:JobNumber & “_4Ft”})
set new_folder33In to (make new folder at JobFolderpath with properties {name:JobNumber & “_33In”})
on error ---- If folders already exist
set new_folder2ft to (JobNumber & “_2Ft”)
set new_folder3ft to (JobNumber & “_3Ft”)
set new_folder4ft to (JobNumber & “_4Ft”)
set new_folder33In to (JobNumber & “_33In”)
end try
try
move (every document file of JobFolderpath whose name contains “_24In.pdf”) to new_folder2ft
move (every document file of JobFolderpath whose name contains “_35In.pdf”) to new_folder3ft
move (every document file of JobFolderpath whose name contains “_48In.pdf”) to new_folder4ft
move (every document file of JobFolderpath whose name contains “_33In.pdf”) to new_folder33In
move (every document file of JobFolderpath whose name contains “_2Ft.pdf”) to new_folder2ft
move (every document file of JobFolderpath whose name contains “_3Ft.pdf”) to new_folder3ft
move (every document file of JobFolderpath whose name contains “_4Ft.pdf”) to new_folder4ft
on error errTxt number errNum
display dialog errTxt & return & errNum
end try
your routine to create the new folders doesn’t work in any cases,
because if the first folder exists and the error occurs, the other folders
won’t be created if they are not present.
I recommend to use a handler to proceed each folder separately, like this:
set new_folder2ft to make_new_folder(JobFolderpath, JobNumber & "_2Ft")
set new_folder3ft to make_new_folder(JobFolderpath, JobNumber & "_3Ft")
set new_folder4ft to make_new_folder(JobFolderpath, JobNumber & "_4Ft")
set new_folder33ln to make_new_folder(JobFolderpath, JobNumber & "_33In")
tell application "Finder"
activate
try
move (every document file of JobFolderpath whose name contains "_24In.pdf" or name contains "_2Ft.pdf") to new_folder2ft
move (every document file of JobFolderpath whose name contains "_35In.pdf" or name contains "_3Ft.pdf") to new_folder3ft
move (every document file of JobFolderpath whose name contains "_48In.pdf" or name contains "_4Ft.pdf") to new_folder4ft
move (every document file of JobFolderpath whose name contains "_33In.pdf") to new_folder33In
on error errTxt number errNum
display dialog errTxt & return & errNum
end try
end tell
on make_new_folder(theFolder, fName) -- theFolder can be either a path string or an alias
try
return ((theFolder as Unicode text) & fName) as alias
on error
tell application "Finder" to return (make new folder at theFolder with properties {name:fName}) as alias
end try
end make_new_folder
Thanks Stefan,
Your right, I didn’t even see or anticipate that.
I couldn’t get your code to work, though your insight put me on the path, and the following seems to work well as far as creating the new folders. I tested by deleting different folders, (first, middle and or last) and the routine didn’t skip a beat.
Its the later part that is stii giving me that pesky -1728 error
Thanks again,
Michael
tell application "Finder"
activate
set folderSufix to {"_2Ft", "_3Ft", "_4Ft", "_33In"} as list
repeat with i in folderSufix
try
make new folder at JobFolderpath with properties {name:JobNumber & i}
end try
end repeat
--- the above works well without error
set new_folder2ft to (JobNumber & "_2Ft")
set new_folder3ft to (JobNumber & "_3Ft")
set new_folder4ft to (JobNumber & "_4Ft")
set new_folder33In to (JobNumber & "_33In")
--- The "move" statement below is giving me fits. Is this a "reference" error?
try
move (every document file of JobFolderpath whose name contains "_24In.pdf") to new_folder2ft
move (every document file of JobFolderpath whose name contains "_35In.pdf") to new_folder3ft
move (every document file of JobFolderpath whose name contains "_48In.pdf") to new_folder4ft
move (every document file of JobFolderpath whose name contains "_33In.pdf") to new_folder33In
move (every document file of JobFolderpath whose name contains "_2Ft.pdf") to new_folder2ft
move (every document file of JobFolderpath whose name contains "_3Ft.pdf") to new_folder3ft
move (every document file of JobFolderpath whose name contains "_4Ft.pdf") to new_folder4ft
on error errTxt number errNum
display dialog errTxt & return & errNum
end try
end tell
Can’t get every document file of alias "PitBat2:Users:PitBat2:Public:Live Jobs:Speedway Job# 1863B:" whose kind ≠"Folder" and name contains "_24In.pdf"
doesn’t match with the script part you posted. Could it have something to do with permissions in the Public folder?
No I use a “chmod -R 777” rutine at the beginning of the script to help with permissions. I have had that problem, since I recieve these files over our ftp server.
All my macs are runnig right now, but I’ll try a few of these ideas in a bit.