Automatic file transfer!

After seeing scripts for automated rsync set up I thought it could be a really easy way to update files but it does quite do what I want it to do. So I have posted this a couple of places but with no responses. So if anyway can help that would be great.

I am trying to develop an applescript that allows a user to put ANY USB pen drive, DVD, CD or external hard drive into a local mac which will then trigger a script to look for the folder “media” in the root of the removable drive or disk. If the folder is there it will bring up a dialogue that will ask the user if they want to update the media on there local machine. They will have 3 options.
Add this will add the files from “media” on the removable drive to a folder on the local mac.
Replace will delete the contents of the folder on the local mac and will then write the files from the removable drive to the local mac.
cancel will cancel the process.
once this is all done the mac ejects the disk and restarts.

I have been trying to adapt the automatic sync scripts that use folder actions on /volumes and rsync but I don’t seem to be able to get them to work, it would be great if someone could help me out. What is really important is that it has to be any drive, I could use Do Something When but I would then need to know which disks I would be using.

So far i think I know how to do the buttons and things but I am stuck with dynamically get the name of the new volume added (when the folder action activates), I have tried to pull apart your rsync script as that searches for the rsync file in the root but I can’t get it to work.

Cheers for any help

Hi Steve,

welcome to MacScripter.

I really don’t understand the exact difference between “Add” and “Replace” in conjunction with rsync.
The default setting of rsync is to move only new or changed files from source to destination and replace the old ones.
You can also tell rsync to delete files at destination which don’t exist at source.

Here is a sample folder action to watch /Volumes with most of your requests.
The script must be located in (~)/Library/Scripts/Folder Action Scripts and be attached to /Volumes (you have to make visible the invisible files and folders).
But because of my lack of understanding I’ve omitted the rsync part

on adding folder items to this_folder after receiving these_items
	set restartFlag to false
	set destinationFolder to ((path to desktop as text) & "Media")
	repeat with i in these_items
		set diskName to name of (info for i)
		if "Media" is in paragraphs of (do shell script "/bin/ls " & quoted form of ("/Volumes/" & diskName)) then
			set restartFlag to true
			set B to button returned of (display dialog "" buttons {"Cancel", "Add", "Replace"})
			if B is "Add" then
				-- do something
			else if B is "Replace" then
				-- do something else
			end if
		end if
		tell application "Finder" to if ejectable of disk diskName then eject disk diskName
	end repeat
	if restartFlag then tell application "System Events" to restart
end adding folder items to