Using the "Keep Both" feature of Finder when moving files

When I drag files from one folder to another in the finder in Mavericks, if there are duplicates, the dialog box gives me the option to click “Keep Both,” which adds a number to the end of the duplicate filename while keeping the extension intact.

Is there a simple way to make this happen in an applescript?

I have been searching and have found lots of interesting stuff, but nothing that will duplicate this functionality.
Embarassingly simple, here’s what I have so far!

property folderA : “Macintosh HD:Somefolder:”
property folderB : “2Tb Backup:Backups:”
property folderC : “Macintosh HD:Problems:”

tell application “Finder”
try
move entire contents of folder folderA to folder folderB without replacing
end try

end tell

Model: iMac
AppleScript: 2.3
Browser: Safari 537.73.11
Operating System: Mac OS X (10.9.1)

No. You need to check if an item already exists, and if so change its name first.

Excellent, thanks for the answer, Shane!

I have been working on that, and actually have more decision points, also. I stumble through the occasional Applescript project about once every 3 years, so I never quite learned it!

I have files starting with a part number, then a dash, then some codes. If the first 6 digits are not a number 100,000 or higher, then I want to kick the file into the Problems folder to deal with manually.

If it passes that test, then I want to move the file to a backup folder, and if there is a duplicate, I want to append it with a number, just to make it unique.

Here’s where I’m at so far, and I feel like a bumbling idiot!! I am trying to work out a kludge of code from other scripts to make this happen!

Any help would be GREATLY appreciated.


property folderA : "Macintosh HD:Users:fmserver:SCAN:"
property folderB : "2Tb Backup:ScanBackups:"
property folderC : "Macintosh HD:Users:fmserver:SCAN:Problems:"
tell application "Finder"
	set thisfolder to folderA as alias
	set mylist to (every file in thisfolder) as alias list
	set thisfolder to thisfolder as text
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "-"
	repeat with eachfile in mylist
		set n to name of eachfile
		set w1 to text item 1 of n
		if w1 < 100000 then
			move n to folderC
		else
			if 
			else
				
			end if
		end if
		try
			
		on error
			
		end try
		
	end repeat
	set AppleScript's text item delimiters to tid
end tell

You probably want:

   if w1 as integer < 100000 then
       move eachfile to folderC

But that’s assuming w1 will be a number. If there’s a possibility it won’t, you’re going to have to deal with that first.

If it’s not a number, then it won’t add up to 100000, correct? I think that will be test enough, am i right? Or am I missing something?

Also, the way I have it written now, it considers the first “word” up to the dash. My concern is that if someone enters 7 digits instead of 6, then the mistake will not be fought. What is the syntax to consider only the first 6 characters of the name?

If it’s not a number, the coercion to an integer will fail and generate an error.

Yes, and handling that error can allow us to move that file into a “Problems” folder. I just don’t know the syntax for it all.

Would someone be interested in helping me write this script?