set originalFile to (choose file)
set newFileName to "bar.txt"
set fileDestination to path to desktop as alias
set movedFile to SpecialMoveRename(originalFile, fileDestination, newFileName)
on SpecialMoveRename(originalFile, fileDestination, newFileName)
set folderRoot to the name of me
set tempPath to path to temporary items as string
set x to 1
repeat
set myTempFolderName to folderRoot & "-" & x as string
try
set myTempFolderPath to (tempPath & myTempFolderName) as alias
set x to x + 1
on error
tell application "Finder"
set myTempFolder to (make new folder at tempPath with properties {name:myTempFolderName}) as alias
exit repeat
end tell
end try
end repeat
tell application "Finder"
set tempFile to (move originalFile to myTempFolder with replacing) as alias
set the name of tempFile to newFileName
set newFile to (move tempFile to fileDestination with replacing) as alias
delete myTempFolder
return newFile
end tell
end SpecialMoveRename