What is the recommended way to create a duplicate of a file and specify the new name?
At the moment I use:
test = Application("Finder").duplicate(Path("/var/tmp/old.txt"), {replacing:true}) // creates "/var/tmp/old copy.txt"
test.name = "new.txt" // renames it to "/var/tmp/new.txt"
I would prefer to specify the output name in that duplicate method, instead of specifying it afterwards. The Finder dictionary says I can use:
duplicate specifier : the object(s) to duplicate
[to: location specifier] : the new location for the object(s)
[replacing: boolean] : Specifies whether or not to replace items in the destination that have the same name as items being duplicated
But when I try the following:
test = Application("Finder").duplicate(Path("/var/tmp/old.txt"), {to:Path("/var/tmp/new.txt"), replacing:true})
- If new.txt did not yet exist, I get the message "Error -1728: Can't get object"
- If new.txt already exists, the message is "Error -1700: Can't convert types"
It is not clear what type "location specifier" is. I tried Path with folder/file/folder+file, regular string (folder/file/folder+file).
Suggestions?