use scripting additions
use framework "Foundation"
on copyFileAt:POSIXPath toFolder:folderPath withReplacing:replaceFlag
set fileURL to current application's class "NSURL"'s fileURLWithPath:POSIXPath
set folderURL to current application's class "NSURL"'s fileURLWithPath:folderPath
-- build path for new file
set theName to fileURL's lastPathComponent()
set newFileURL to folderURL's URLByAppendingPathComponent:theName
set fileManager to current application's NSFileManager's defaultManager()
set theResult to fileManager's copyItemAtURL:fileURL toURL:newFileURL |error|:(missing value)
if not (theResult as boolean) and replaceFlag then
fileManager's removeItemAtURL:newFileURL |error|:(missing value)
-- or move to Trash: fileManager's trashItemAtURL:newFileURL resultingItemURL:(missing value) |error|:(missing value)
set theResult to fileManager's copyItemAtURL:fileURL toURL:newFileURL |error|:(missing value)
end if
return (theResult as boolean)
end copyFileAt:toFolder:withReplacing:
its copyFileAt:"/Users/shane/Desktop/Testing.png" toFolder:"/Users/shane/Desktop/Test Folder" withReplacing:true