ApplesScript to change image file name from a pre-defined list

Hopefully one of the AppleScript gurus on here can help with my request. I have no scripting skills beyond being able to tweak code I have found, and I can’t find anything for this request.

I would like an AppleScript droplet, which runs when an image is dropped onto it renaming the image file. The new name comes from a predefined list (examples below) retaining the original file details.

Once the list of names reaches the last in the list the script should re-start, and simply cycle through the list again. The images will be dropped automatically and remotely.

An example using the property list below. Image IMG_001.JPG is dropped onto the applet, the script runs and allocates the first name in the list, so that it now becomes London-Bridge-Saturday-IMG_001.JPG

Ideally, an option to automatically add the dashes or remove them would be useful, or simply what is defined within the list is used in the format written.

Also, I’d like to send an iMessage once the process is complete or if it fails. An ability to turn on/off messaging would be useful.


property thePicName : {"London-Bridge-Saturday-", "Tower-of-London-Saturday", "BT-Tower-London"} #Rename drop image files. Retain original image ID i.e. IMG_001.jpg. Cycle through the list and restart at one if needed.

I hope someone can help.

I found the following, and have tried to make it work. However, I get the error below.

Also, I can’t see how to retain the existing file name and format, or how to restart from the first name in the list.



use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions


property theFileTypesToProcess : {"jpg"} -- For example: {"PICT", "JPEG", "TIFF", "GIFf"}
property theExtensionsToProcess : {"jpg"} -- For example: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property theTypeIdentifiersToProcess : {"example-one-.jpg", "Example-2-.jpg"} -- For example: {"public.jpeg", "public.tiff", "public.png"}

on open theDroppedItems
	repeat with a from 1 to count of theDroppedItems
		set theCurrentItem to item a of theDroppedItems
		tell application "System Events"
			set theExtension to name extension of theCurrentItem
			set theFileType to file type of theCurrentItem
			set theTypeIdentifier to type identifier of theCurrentItem
		end tell
		if ((theFileTypesToProcess contains theFileType) or (theExtensionsToProcess contains theExtension) or (theTypeIdentifiersToProcess contains theTypeIdentifier)) then
			processItem(theCurrentItem)
		end if
	end repeat
end open

That’s suggesting your script doesn’t have an “on processItem(anItem)” handler. Does it?