Toggle File Extension on MacOS

This is something that’s bothered me for as long as I can remember. While I believe that MacOS is objectively a much better OS than Windows, admittedly, there are just some things that Windows does better. This is especially true for right-click context menus in Finder. Windows File explorer offers a helpful selection of actions you may want to do, where MacOS is blatantly silent.

Windows 10 Right-Click Context Meny
MacOS Right-Click Context Menu

By default, file extensions are turned off, but it’s possible to turn them on. The trouble with turning on file extensions is it’s an all-or-nothing deal in the worst-case scenario, and the lesser evil is manually turning on the file extension one file at a time. That’s fine if you want to see an occasional file extension here or there, but it is a tedious process for such a trivial thing.

In most cases, I don’t want/need to see file extensions, but I work a lot with images, and I like to see the file extension, so at a glance, I can see tell which are PNG and which are JPG files.

Every now and again, in a fit of frustration, I would waste hours trying to find a solution to my problem. Google returned less than helpful results, and in the end, I would just grumble and give up.

Enter Automator Quick Actions…

Automator and AppleScript and Quick Actions, Oh My!

1. Launch Applications > Automator

2. Choose New Document > Quick Action, then click Choose.

3. Drag and drop the Run AppleScript action from the Utility Library onto the workflow window.

4. Remove the default content from the Run AppleScript action, and copy/paste the script code (below) into the editor window.

5. Click the hammer icon in the Run AppleScript action.

6. Configure the top of the Quick Action as you see in this finished example below.

7. Save the Quick Action as Toggle File Extension.

8. Quit Automator.

9. Enjoy your shiny new toggle action!

Automator Script Code


use scripting additions

on run {input, parameters}
	
	tell application "Finder"
		
		repeat with anItem in input
			set ext_status to extension hidden of item anItem
			
			if ext_status then
				set extension hidden of anItem to false
			else
				set extension hidden of anItem to true
			end if
		end repeat
		
	end tell
	
	return input
end run

Special thanks to VikingOSX over on the Apple Community Forums.