Change File Extension of Dropped Items

Hello all,
I am trying to make a script that allows you to change the file extension of an item (pictures in this case), but I keep on getting the error:

Can’t set «class extn» of alias to “jpg”.
System Events got an error: Can’t set name extension of alias to “jpg”. (-10006)

Here is my code so far:

on open droppedItems
	repeat with a from 1 to count of droppedItems
		set currentItem to item a of droppedItems
		tell application "System Events"
			set itemExtension to the name extension of currentItem
		end tell
		
		
		set displayOptions to choose from list {".jpg", ".png", ".tiff", ".pdf"}
		if ".jpg" is in displayOptions then
			tell application "System Events"
				set the name extension of currentItem to "jpg"
			end tell
		end if
		
	end repeat
end open

Thank you in advance for any help, it would be greatly appreciated.

-CamSox

name extension in “System Events” is read-only property. You must use “Finder” instead


open {choose file of type {"public.image"}} --this code line I add only to test dropplet--remove it or comment for real dropplet 

on open droppedItems
	repeat with a from 1 to count of droppedItems
		set currentItem to item a of droppedItems
		set displayOptions to choose from list {".jpg", ".png", ".tiff", ".pdf"}
		if ".jpg" is in displayOptions then tell application "Finder" to set the name extension of currentItem to "jpg"
	end repeat
end open

Note: If your goal is to standardize the extensions of all image files, then there is a better way than this droplet: using Uniform Type Identifiers (named UTI, all image files has UTI “public.image”)

Thank you so much KniazidisR, much appreciated!

Nice tip! Logging this one for future use.