Hi,
i have a proplem with my folderaction, when a filename already exists in the “DoneFolder” - i would like to rename the new pdf in “test.pdf1” , “test.pdf2” , “test.pdf3” …
How can i do that?
Many thanks for your help!
property done_foldername : "Printed"
on adding folder items to this_folder after receiving added_items
tell application "Finder"
if not (exists folder done_foldername of this_folder) then
make new folder at this_folder with properties {name:done_foldername}
end if
set the target_folder to folder done_foldername of this_folder
end tell
repeat with thisFile in added_items
tell application "Finder"
set fileName to name of thisFile
if fileName ends with ".pdf" then
set the target_file to (move thisFile to the target_folder) as alias
tell application "Acrobat 5.0"
open thisFile
print pages front document with shrink to fit
close front document
end tell
end if
end tell
end repeat
end adding folder items to
Try inserting this between your ‘if fileName ends with…’ and ‘set the target_file to…’ lines:
set suffix to (count (files of target_folder whose name begins with fileName))
if (suffix > 0) then
-- If there are any files in the target folder whose names begin with the
-- current file name, make a new name from the file name and their number.
set newName to fileName & suffix
-- That should be good enough, but check the new name's free in case the
-- count was reduced by the removal of files from the target folder.
set matchingNames to (name of files of target_folder whose name begins with fileName)
repeat while (newName is in matchingNames)
set suffix to suffix + 1
set newName to fileName & suffix
end repeat
-- Rename the current file before moving it.
set name of thisFile to newName
end if