Process 2 images with a specific naming convention?

I have a script saved as an app that processes 2 image files. They both have the same name but one of them has “@2x” at the end. For example “myimage.png” and “myimage@2x.png”

At the moment I drop the first image onto the app (“myimage.png”), and it pops up a prompt to choose the second image (“myimage@2x.png”). It then runs a shell script on both of them.

What I’d like to do if possible is drop both images onto the app and it would set the first image (“myimage.png”) to “normalImage” and the second image (“myimage@2x.png”) to “retinaImage” by somehow reading the name, so that you don’t have to drop the single image first onto the app and then select the second one afterwards.

Here’s the script;

on open these_items
    
    set normalImage to POSIX path of these_items
    set retinaImage to POSIX path of (choose file with prompt "Select the @2x version of your image:" of type {"png"} default location (path to desktop folder))
    tell application "Finder" to set ImageName to text 1 thru -5 of (get name of file these_items)
    set combinedTIFF to POSIX path of (path to desktop folder) & ImageName & "_retina.tiff"
    
    do shell script "tiffutil -cathidpicheck" & space & quoted form of normalImage & space & quoted form of retinaImage & space & "-out" & space & quoted form of combinedTIFF
    
end open

Any help would be appreciated.

Hi,

this is a different solution: Drop one or multiple “normal” images onto the droplet.
The script looks for the @2x file in the same folder and combines the image(s).
If the @2x file does not exist in the same folder the image is skipped


on open these_items
	repeat with anItem in these_items
		set normalImage to contents of anItem
		tell application "System Events" to set {name:fileName, name extension:nameExtension, container:parentFolder} to normalImage
		if nameExtension is missing value then set nameExtension to ""
		if nameExtension is not "" then set fileName to text 1 thru ((count fileName) - (count nameExtension) - 1) of fileName
		
		set retinaImage to (path of parentFolder) & fileName & "@2x." & nameExtension
		try
			retinaImage as alias -- test if @2x file exists
			set combinedTIFF to POSIX path of (path to desktop folder) & fileName & "_retina.tiff"
			do shell script "tiffutil -cathidpicheck" & space & quoted form of POSIX path of normalImage & space & quoted form of POSIX path of retinaImage & space & "-out" & space & quoted form of combinedTIFF
		end try
	end repeat
end open

That works great, thanks a lot! :smiley: