image copy, resize and append size to name

In view of my (yet) lacking scripting skills, I’d like to ask the help of you seasoned DTPO’ers!

I’m working on a technical report with a heap of digital photos. As you all know the size of nowadays photos doesn’t make it easier on our tools…
Therefore I’ve come up with the idea of using the image scaling scripts to help out.

I’ve adapted the script as follows:

-- Scale  to 200 pixels
-- Created by Christian Grunenberg on Tue Apr 27 2004.
-- Adapted by PanE on Tue Nov 22 2016
-- Copyright (c) 2004-2014. All rights reserved.
-- Based on (c) 2003 Apple, Inc.

tell application id "DNtp"
	try
		set this_selection to the selection
		if this_selection is {} then error "Please select some images."
		repeat with this_item in this_selection
			if the type of this_item is equal to picture then
				try
					set this_image to the image of this_item
					with timeout of 30 seconds
						tell application "Image Events"
							launch
							set this_file to open file this_image
							scale this_file to size 200
							save this_file without icon
							close this_file
						end tell
					end timeout
					synchronize record this_item
				end try
			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

Now what I would like to achieve is:

  • instead of scaling the original, I’d like to scale a copy.
  • append _scale to the name so it becomes > picture_200.jpg

The idea being that all images from the same source will be listed together, and it will be easy to pic the correct size for the purpose.

Thanks for helping out!

Here is a snippet that will duplicate and rename the duplicate.

tell application id "DNtp"
	set oldRecord to the first item of (the selection as list)
	set newRecord to duplicate record oldRecord to the current group
	set the name of newRecord to (name of oldRecord & "_200")
end tell

If you are displaying names of documents with their extension you’ll need to Google for a script, or grab one of the scripts here, that strips extensions from names. (Sorry, you’ll need to do your own homework on that one.) Or simply first use the built-in Rename > Replace Text… script first to remove the “.jpg” or “.jpeg” extension from your files before running your custom script.

Korm, thanks a lot for dropping in!

I miss the point: what’s the problem with the extension? I don’t get it.
It is true that I prefer to ALWAYS see the extensions. Stems from ‘only trust your eyes’…

If the document’s name is “Prize.jpg” because you set the preference Import > Titles > Filename with extension, then if you use the snippet it will rename the file “Prize.jpg_200”. I could fix this, but I’m too lazy today :laughing:

Ha, Now I get it!
You could ad you account number… :smiling_imp: :laughing: