Batch image rename with pattern

I just published an Applescript on Github (“Image auto-rename and annotate.applescript”), that renames selected images according the scheme

img######

I.e., the new names will consist of “img” and a running number. The number will be increased every time the script is run. In this way, each renamed image file gets a unique file name. This reduces file name ambiguity which, e.g., becomes a crucial point when using DEVONthink’s WikiLinks feature. It also makes images better distinguishable from other files in DEVONthink’s search.

The original file names will be stored in the images’ Finder comments for which the script offers the following options:

Replace with current image name: The current comment will be replaced by the current image name.

Replace with custom text: The current comment will be replaced by a custom text.

Replace with custom text + increasing number: The current comment will be replaced by a custom text and an increasing number will be attached to that text.

Don’t replace current annotation: The current comment will not be replaced.

Remove current annotation and leave empty: Removes the current comment and leaves it empty.

Add current image name: The current image name will be added to the current comment.

Add custom text: A custom text will be added to the current comment.

Add custom text + increasing number: A custom text with an attached increasing number will be added to the current comment.

Please, find further instructions for the script in the repository’s README file.

This script is part of my image workflow for Markdown files. A second script creates Markdown/HTML image link sets and reuses the stored Finder comments as optional image captions.

3 Likes

Thanks for this and the other scripts! I just had a look at the JPEG compression and DPI scripts of your toolbox and noticed that you use a shell script to process the images, therefore it’s actually not necessary anymore to script “Image Events” too. E.g. JPG compress XY% could be simplified like this:

tell application id "DNtp"
	try
		set this_selection to the selection
		if this_selection is {} then error "Please select some images."
		set dialogResult to display dialog "Please enter a JPEG compression level (in %)." buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" default answer ("70") with title "Choose JPEG compression"
		set theCompression to text returned of dialogResult
		
		repeat with this_item in this_selection
			if the type of this_item is equal to picture then
				set thePathShell to quoted form of (the path of this_item as string)
				-- formatOptions normal normal means "normal" compression (70%? 80%?). You can also set a number (w/o "%", e.g. 100 (=loss-less))
				do shell script "sips -s format jpeg -s formatOptions " & theCompression & " " & thePathShell
				synchronize record this_item
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell
1 Like