I have lost the count how many times I have read the ‘reference guide’ of this method.
Could someone explain in words of a child in mind, I’m lost.
Here is the code.
use framework "Foundation"
use scripting additions
(**
* [Class]: NSFileManager
* A convenient interface to the contents of the file system,
* and the primary means of interacting with it.
**
* [Instance Method]: replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:
* Replaces the contents of the item at the specified URL in a manner
* that ensures no data loss occurs.
**
* - (BOOL)replaceItemAtURL:NSURL withItemAtURL:NSURL backupItemName:NSString
* options:NSFileManagerItemReplacementOptions resultingItemURL:NSURL
* error:NSError
*)
set thePath to POSIX path of (path to desktop) & "123.tiff"
set theDest to POSIX path of (path to desktop) & "123 copy.tiff"
set theBackupName to "123.bak"
my replaceItemAtURL:thePath withItemURL:theDest backupItemName:theBackupName resultingItemURL:theDest
on replaceItemAtURL:_originalItemURL withItemURL:_newItemURL backupItemName:_backupItemName resultingItemURL:_resultingURL
set theSource to current application's |NSURL|'s fileURLWithPath:_originalItemURL
set theDestination to current application's |NSURL|'s fileURLWithPath:_newItemURL
set theBackupName to current application's NSString's stringWithString:_backupItemName
set theResultingItem to current application's |NSURL|'s fileURLWithPath:_resultingURL
set filemanager to current application's NSFileManager's defaultManager
set {theResult, theError} to filemanager's replaceItemAtURL:theSource withItemAtURL:theDestination backupItemName:theBackupName options:0 resultingItemURL:theResultingItem |error|:(reference)
return {theResult, theError} as list
end replaceItemAtURL:withItemURL:backupItemName:resultingItemURL: