on run
tell application "Finder" to set fileList to the selection
set destFolder to (path to documents folder) as text
repeat with fn in fileList
set fn to fn as alias
tell application "System Events"
set newName to name of disk item (fn as text)
if exists disk item (destFolder & newName) then set newName to my buildNewName(newName)
end tell
set originalFile to quoted form of (POSIX path of fn)
set newFile to quoted form of (POSIX path of (destFolder & newName))
do shell script "cp -n -p " & originalFile & space & newFile
tell application "System Events" to delete disk item (fn as text)
end repeat
end run
on buildNewName(f)
set AppleScript's text item delimiters to "."
set l to text items of f
set newName to (items 1 thru -2 of l) as text
set ext to item -1 of l
set AppleScript's text item delimiters to ""
return newName & (do shell script "date +_%Y%m%d-%H%M%S") & "." & ext
end buildNewName
And I assume that there is a Shell commant able to replace the use ot System Events to delete the original file.
Yvan KOENIG (VALLAURIS, France) samedi 10 octobre 2009 13:22:21