Tagging Images Not Matching Certain Criteria

Hey Everyone,

I have been using Automator to check image files for a long time now but have wanted to switch it over to keyboard maestro and now seems to be a good time with the impending switch from Automator to "Shortcuts". The biggest issue with switching programs has been figuring out how to implement the AppleScripts setup in Automator within KM. Currently have two AppleScripts each one checking a different image property and tagging items in the Finder that match the criteria. I didn't write the AppleScripts for the Automator so not sure how they work/how I can implement them (*using KM variables as input).

Image properties to check:

  1. Dimensions of the image match 2000px x 2667px or 36px x 36px (Tag yellow if not)
  2. Image resolution matches 72 PPI (Tag green if not)

The third check I haven't been able to implement is tagging image files that are not using the sRGB colour profile. Please let me know how I can implement these Applescripts or if there is a better way of doing this.

Applescript used to check dimensions

on run {input, parameters}
   set final_list to {}
   repeat with ea_ch in input
      try
         tell application "Image Events"
            close images
            set b to open (ea_ch as alias)
            set c to dimensions of b
            set d to resolution of b
            close b
         end tell
         if not (((c's item 1) * (c's item 2)) = 5334000 or ((c's item 1) * (c's item 2)) = 1296) then set end of final_list to (ea_ch as alias)
      end try
   end repeat
   return final_list
end run

AppleScript used to check PPI:

on run {input, parameters}
   set final_list to {}
   repeat with ea_ch in input
      try
         tell application "Image Events"
            close images
            set b to open (ea_ch as alias)
            set d to resolution of b
            close b
         end tell
         if not (((d's item 1) * (d's item 2)) = 5184 or ((d's item 1) * (d's item 2) = 5184)) then set end of final_list to (ea_ch as alias)
      end try
   end repeat
   return final_list
end run

Hey @theandouz,

What's the input? Selected files? Every file on the HD? ...

-Chris

Hey @ccstone,

A selected folder containing images. Needs to be able to check images in subfolders

Main Folder (selected folder)

  • subfolder 1
    • image 1
    • image 2
  • subfolder 2
    • image 3
    • image 4

How many items are there likely to be at any one time?

What kind of images? Any and all? Or a specific type?

It varies by the day but can range from 100 - ~1000 images, Automator usually take a minute to process the files so I know it won't be an instant process

Only checking jpg images, no other types should be within the folders

Hey @theandouz,

Here's the first script.

-Chris


Finder ⇢ Recursively Tag Images “Yellow” if NOT a 2000x2667 or 36x36 in Dimension in the Selected Folder v1.00.kmmacros (10 KB)

Hey @theandouz,

Here's the second script.

-Chris


Finder ⇢ Recursively Tag Images “Green” if Resolution is NOT 72dpi in the Selected Folder v1.00.kmmacros (10.0 KB)

Awesome thanks for your help with this! How do I run the script just select the folder in Finder and run it with the keyboard shortcut? (Does it automatically pull the files from the folder?)

Also, is it possible to send a list of files through the script using a variable? I.e.

KM__ListOfFilesVariable:
/Users/Desktop/06_14_2020/subfolder 1/file1.jpg
/Users/Desktop/06_14_2020/subfolder 1/file2.jpg
/Users/Desktop/06_14_2020/subfolder 2/file1.jpg
/Users/Desktop/06_14_2020/subfolder 2/file2.jpg

Note that there are better ways to do this than to use Image Events. (Image Events is deprecated.)

Keyboard Maestro can do it entirely with native actions, and there are command line tools that are purpose built for this kind of thing.

I don't want to invest the time building this though.

I am looking in to using AppleScriptObjC to get the image information. If that can be done then the script can be sped up by a large factor.

-Chris

Correct.

What do you mean?

The script recursively finds jpg image files in the folder selected in the Finder and tags them appropriately.

Not with the scripts I posted.

But they can easily be modified to take a Keyboard Maestro variable as input.

-Chris

I didn't realize Keyboard Maestro could do this natively, however after some looking around I found someone on the forum using a shell script to get the dimensions of a video and after some googling found I could also use it for photos. Attaching how I setup the script, any comments/improvments are welcome!

Tag Images that don't match set Resolution/Dimensions Macro (v9.2)

Tag Images that don't match set Resolution-Dimensions.kmmacros (16 KB)

Get Image Info v1.00.kmmacros (7.9 KB)

In the Keyboard Maestro Editor you can hit K to bring up the Action-Inspector Panel.

There's a whole category for “Images”.

You can also use the Search field in the Help menu to find matching items.

You can also hit A to bring up the Insert Action by Name dialog.

image

Holding down the Option-key in menus will let you go to the Wiki page for that item.

You can right-click actions in the working macro and get help for them.

Keyboard Maestro Wiki

So don't forget your due-diligence when looking for features.  :sunglasses:

-Chris

I really appreciate you taking the time to write those initial scripts! I'm usually pretty good with searching the wiki and solving my macro problems but I got stuck trying to reimplement the AppleScripts and I just didn't think KM could pull the image properties natively. But again I do appreciate all your help! :blush:

Thanks!
-Andrew

1 Like

Hazel can do all that out of the box. It's a great addition to KM.
I do something similar: