How I can delete an image (move it into the trash) from applescript by giving the filename and path of the image locate on the drive.
This script will be started from the shell and may get the (valid) filename including the path (size or other properties if needed) as parameter.
So far I could manage to select the image by name (which is the filename usually) and set a comment on it. So I can search for that comment and delete all images with that comment at once. But with random image names this is not possible because you find unrelated pictures for the name.
Philip has the right idea, but is making things a little harder than they need to be. :) The following does the trick for me:
This grabs the first command line argument and uses it as the file path you want to delete. Since a photo in iPhoto can have both a modified and an original copy of each photo, the script tests for both the photo's original path and its current image path when looking for which photo to delete.
Do note though that the "original path" property only exists in iPhoto 8.x, so if you have an earlier version of iPhoto, you'll need to take that part out and be able to provide the correct photo path (the one in the Modified folder if there is one, otherwise the path in the Originals folder).
Also, the reason the "remove" command works whereas "delete" does not is because iPhoto sucks - "delete" really should work!