Can a script run when you mount a new disk?

I have built a script that essentially copies the contents of flash drive into a folder, deletes the contents and ejects the disk. Is there any command at all that can run automatically when the flash drive mounts? I want to be able to plug the drive in, have the action occur and then have the action remove the disk. Is running a script automatically when the drive mounts possible?

What I would like MOST of all, is if I have a script that resides on a flash drive OR a cd etc. When the disk mounts, the script plays FROM the drive. That way I can take the drive to any computer and have it work. Is this possible? Any help with the command if there is on would be GREATLY appreciated!

-i

I haven’t thought of a way to make the AppleScript start itself (though there may be one), but if you move the files from the flash drive to folder with the drive plugged in, you won’t have to erase the drive, you can just eject it.

Thanks Adam,

I found my answer after trying a number of serach terms at the following location: HERE

I think that this solved at least one of my objectives which is getting a CD ROM to run an APP as soon as it is installed (intercative CD ROM)

Unfortunately, it doesn’t solve my second objective. With my photograpy I am constantly swapping out 2GB compact flash cards, and I would love to be able to slap one in and walk away while I continue to shoot (hence why I delete the files). I guess I will have to waste those extra 4 seconds of double clicking an APP.

As far as “DELETING” is concerned, is there and way JUST to delete the contents of a folder or drive? When I use the “delete” command it simply moves the files to the trash. I don’t want to empty the ENTIRE trash, just the files that were on a specific disk or in a specifc folder. If I don’t empty the trash then the external drive still registers the space occupied.

-i

Not sure what you found, but this will empty everything from a stick except the AppleScript.app on the stick and then empty the trash to free up the stick’s memory. (I saved it as an app named MoveFiles on the stick)

tell application "Finder"
	set src to (every file of disk "Your-Stick" whose name extension is not "app") as alias list -- doesn't move the script.app
	set dest to alias "path the the destination folder"
	duplicate src to dest with replacing
	move src to trash
	delay 0.2 -- trashing takes a moment
	empty
end tell

Thanks again Adam,

I understand the “empty” command, I just wanted to find some way to empty the trash ONLY of the items that came from the disk, not all the other items in the trash. Probably not possible.

is “delay”? really necessary? I haven’t encountered any issues yet without it.

I’ll try to stop bothering you.

-i

If I don’t put the delay in, the script failed occasionally with a “somefile.jpg in use” error - it was still being moved.

You can certainly look at the contents of the trash before the duplicate and move to trash, duplicate them to a temp folder, duplicate the files, move them from the stick to the trash, empty the trash of the duped files, and move the temps back to the trash.

You’re not bothering me at all. Reasonable questions.