Script to copy files to a certain location and overwrite old ones

Hi,

I have almost zero experience with scripts so I’m looking for someone who can help me with this:

I have daily tasks that involve copying a few files to a certain location and overwriting the old ones.
So let’s say I have a master folder called FILES. Inside, I have the folders AUDIO and IMAGES, each with certain files.

Every day, I have to go to another folder that has the same structure, but just a different location. I would like to select some files from AUDIO and some from IMAGES, right click, Services, and run a script that would read my selection of files and if a file is called “audio.wav”, it will copy it to my FILES>AUDIO folder and automatically replaces the old one, without asking me anything. Then if the other files are “image1.jpg”, “image2.jpg”, and “image3.jpg”, it will send a copy of them to FILES>IMAGES and automatically replaces the old ones, without asking me anything.

Is this possible?

Thanks :slight_smile:

AppleScript: 2.11
Browser: Safari 605.1.15
Operating System: macOS 10.15

tiagorocha1979. The following script will do what you want; some simple error checking needs to be added if that’s desired. I explained in one of your other threads how this script can be run by way of the right-click menu. If you decide to do that, the line that begins with “set selectedFiles” would need to be modified to “set selectedFiles to input” (omit quotes).

set imageFolder to (path to desktop as text) & "Images"
set audioFolder to (path to desktop as text) & "Audio"

tell application "Finder"
	set selectedFiles to selection as alias list
	repeat with aFile in selectedFiles
		if (name extension of aFile) = "wav" then
			duplicate aFile to folder audioFolder with replacing
		else if (name extension of aFile) = "jpg" then
			duplicate aFile to folder imageFolder with replacing
		end if
	end repeat
end tell