Replacing File prompt if file exists? Show thumbnail?

This is the working script that I currently use.

-- to include all file types

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "psd"}

--this sorts the files by the begining of thename of the file
--if they contain

tell application "Finder"
	set theHotFolder to folder "Hal 9000:Users:matthew:Pictures:HotFolder2do"
	
	move (files of theHotFolder whose name starts with "BU") to (get first folder of desktop whose name starts with "2_do_Burton")
	
	-- this moves every "BH...." and "CC...." files  to folder "2_do_BHS..."
	move (files of theHotFolder whose name starts with "BH" or name starts with "CC" or name starts with "AL" or name starts with "AL" or name starts with "SM") to (get first folder of desktop whose name starts with "2_do_BHS")
	
	--- another example
	move (files of theHotFolder whose name starts with "FR") to (get first folder of desktop whose name starts with "2_do_Freedom")
	move (files of theHotFolder whose name starts with "ES") to (get first folder of desktop whose name starts with "2_do_Daisy")
	move (files of theHotFolder whose name starts with "DV") to (get first folder of desktop whose name starts with "2_do_DIVA")
	move (files of theHotFolder whose name starts with "GT") to (get first folder of desktop whose name starts with "2_do_Gina")
	move (files of theHotFolder whose name starts with "TM") to (get first folder of desktop whose name starts with "2_do_Top")
	move (files of theHotFolder whose name starts with "WA") to (get first folder of desktop whose name starts with "2_do_Wallis")
	move (files of theHotFolder whose name starts with "PR") to (get first folder of desktop whose name starts with "2_do_Press")
	-- this moves every "DJ...." and "RA...." files  to folder "2_do_Dorothy...."
	move (files of theHotFolder whose name starts with "DJ" or name starts with "RA") to (get first folder of desktop whose name starts with "2_do_Dorothy")
	-- this moves every "MA...." and "MF...." files  to folder "2_do_Dorothy...."
	move (files of theHotFolder whose name starts with "MA" or name starts with "MB" or name starts with "MF" or name starts with "FI" or name starts with "MC") to (get first folder of desktop whose name starts with "2_do_Matalan")
end tell

This works fine, but if a file already exists in the destination folder, it stops. Can I get a prompt to come up saying overwrite file in destination or remove from the folder theHotFolder?

The even better way would be if I could use the thumbnail of the image so you could compare the 2 images to decide which image I should keep, a bit like how iPhoto works when importing images.

Yes, of course. It looks like file with prefix 1 always goes into folder with prefix A. If yes, you could put those prefix pairs into a list of lists. Use a repeat loop to act on each pair. The move command has a modifier replacing yes/no, which controls overwriting. Put the move command into a subroutine, as it is needed twice: once when no duplicate is found, and once when the “overwrite yes/no” dialog has come up. Here’s a partial solution:

property partialPathToHotFolder : "Pictures:HotFolder2do"
property Prefixes : {{"BU", "2_do_Burton"}, {"file prefix", "folder prefix"}}


tell application "Finder"
	set theHotFolder to folder partialPathToHotFolder of home -- this makes it portable (depending on the presence of the folders used)
	
	repeat with thesePrefixes in Prefixes
		-- (I'm not so happy with all these very similar variable names)
		-- 'contents of' gives you the actual text, not a pointer to the item
		-- (which has confused me lots of times :grin:)
		set thisFilePrefix to contents of item 1 of thesePrefixes
		set thisFolderPrefix to contents of item 2 of thesePrefixes
		
		set filesTomove to (files of theHotFolder whose name starts with thisFilePrefix)
		set destFolder to (get first folder of desktop whose name starts with thisFolderPrefix)
		
		repeat with anItem in filesTomove
			if exists anItem in destFolder then -- ask what to do
				-- (file reference may coerce to text automatically?)
				set nextAction to text returned of (display dialog "File '" & anItem & "' exists." & return & "Overwrite or skip?" buttons {"Cancel", "Overwrite", "Skip"} default button 3)
				(*
						if nextAction is ....etc
							cancel > tell me to quit
						else if
							overwrite > move routine with overwrite = yes
						else
							skip:
							exit repeat = do nothing, and leave original in place
							OR trash anItem
						end if
				*)
			else -- move it
				my moveItem(anItem, destFolder, no) -- 'no' is a constant, not text!
			end if
		end repeat -- of moving files
	end repeat -- of doing prefixes
end tell

on moveItem(theItem, destFolder, overwrite)
	tell application "Finder"
		move theItem to destFolder replacing overwrite
	end tell
end moveItem

I’m quite sure this will be much slower than your current script.

Not with vanilla A/S, or you’d have to tell an app (Preview? Image Events?) to open both images, then select one in a dialog. Pashua can display images directly from a script, but you must really love scripting to go there :wink: - not that it’s that hard.

I know you can write your own. Is there a way of triggering the finder alert from moving a file with AppleScript ?

I’m not sure I understand. You can put the move command in a try block, and the alert will not appear.
Add an on error section, and do what you want with the error.

Or do you want to see the alert without actually moving a file on top of itself?
Check out display alert in Standard Additions.

At least on my machine running snow leopard, when I drag a file to a folder which contains another file with the same name, an alert triggers. I understand that you can write your own alert within a try block. My question is if there is a way to trigger the same alert that occurs if you simply drag and drop a file in the finder, from AppleScript.

I have found a thread that already explored this topic:
http://macscripter.net/viewtopic.php?id=28628

Ah, yes. Catching the error in a try block is the only way, like in Stefan’s post in that thread. No getting at a Finder resource (if that’s what that window is - probably not). Unless, maybe, with ASObjC Runner??

That’s not going to be able to make the Finder behave differently to how it’s been programmed, which is what this request really amounts to. But you could make a visually identical dialog.