script that deletes files with same name, but different extension

Hey guys,

thanks for supporting me on this.

I’m looking for a script which does the following:

delete files of the same name, but different extension, of what is currently selected.

Background: I’m shooting photos with my DSLR in RAW+JPEG mode, i.e. the camera stores the RAW version of the image, but also a “developed” JPEG version of it. What I need the script for is: when I browse the pictures later on the Mac and want to delete some of them, I always have to delete the RAW versions too…

Now, what I would like to be able to do is: select a number of JPEG files and execute a context menu item (using OMG) that will then delete [as in move to trash] the selected JPEGs as well as their RAW “siblings” (they have the extension .ARW) . . . .

Shouldn’t be too difficult, should it? Thanks guys !!!

Hi floz,

this script should do it.
Save it as application, then you can drop files onto it or run it normally.
Open it you will prompted to select the files

on run
	set these_items to (choose file with prompt "choose files to delete" with multiple selections allowed without invisibles)
	delete_files(these_items)
end run

on open these_items
	delete_files(these_items)
end open


on delete_files(these_items)
	repeat with this_item in these_items
		set {folder:Fl, name:Nm, name extension:Ex} to (info for this_item)
		if Fl is false then
			if (Ex is missing value) then set Ex to ""
			set Nm to {Nm, Nm's text 1 thru (-2 - (count Ex))}'s item (((Nm contains ".") as integer) + 1)
			tell application "Finder"
				try
					delete file (Nm & ".ARW") of container of this_item
				end try
				delete this_item
			end tell
		end if
	end repeat
end delete_files


Alright, that looks great, thanks! However, is it possible to have the script run from within a finder context menu?

I.e. using the little thumbnails in the finder, I have selected a number of JPGs. Now, how do I set up OMC to execute your script to delete the currently selected files?

this code should do it, but it doesn’t work in OMC :frowning:
Maybe you know OMC better than me to find out why


tell application "Finder"
	activate
	set these_items to selection
end tell
repeat with this_item in these_items
	set {folder:Fl, name:Nm, name extension:Ex} to (info for this_item as alias)
	if Fl is false then
		if (Ex is missing value) then set Ex to ""
		set Nm to {Nm, Nm's text 1 thru (-2 - (count Ex))}'s item (((Nm contains ".") as integer) + 1)
		tell application "Finder"
			try
				delete file (Nm & ".ARW") of container of this_item
			end try
			delete this_item
		end tell
	end if
end repeat