Hello
Here is a script I uses from time to time:
--[SCRIPT] set sourceFile to choose file set destFolder to choose folder
tell application "Finder" set origName to name of sourceFile if not (exists file ((destFolder as text) & origName)) then duplicate sourceFile to destFolder else set tempFolder to (path to "temp" from user domain) as alias set tempFile to duplicate sourceFile to tempFolder set unique to my buildUniqueName(destFolder, sourceFile) set name of tempFile to unique move file ("" & tempFolder & unique) to destFolder end if end tell
-- ==========
on buildUniqueName(df, sf) local n1, xn, begName, n, n2, newPath tell application "Finder" set n1 to name of sf try set xn to "." & (name extension of sf) set begName to text 1 thru (-1 - (length of xn)) of n1 on error set {xn, begName} to {"", n1} end try set n to 1 repeat set n2 to ¬ begName & (text -4 thru -1 of ("0000" & n)) & xn set newPath to "" & df & n2 if exists file newPath then set n to n + 1 else exit repeat end if end repeat end tell -- to Finder return n2 end buildUniqueName -- ========== --[/SCRIPT]
|