Check/Uncheck "Hide Extension" Status of an Item in the Finder

I have occasion to turn the "Hide extension" box in Finder on and off frequently. I don't see that the OS provides a way to do that other than by mouse. I would like to automate it via KM. It seems it should be a simple process, but I'm struggling.

The first step is to open the Get Info panel. That one's simple enough, but I've been unable to get a mouse to click the checkbox reliably. I'm hoping someone can help guide me to how best to get a mouse to click a static box reliably.

Keyboard Maestro can handle this with a macro that uses the Execute An AppleScript action.

The example below will toggle the file-extension visibility of the files selected in the Finder.


The AppleScript code:

tell application "Finder"
   set _files to selection as alias list
   if _files is {} then return display alert "Nothing selected!" as warning giving up after 5
   repeat with f in _files
      set extension hidden of f to (not extension hidden of f)
   end repeat
   set selection to _files
end tell
1 Like

Superb! Thank you.

Thanks, @NaOH, for your elegant solution!