Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to hide file extension using Automator or Finder Service?

I am trying to create a Quick Action that will let me show/hide the file extension on a selected file(s)


It doesn't have be a Quick Action in the right-click context menu, it could be a script I can add to to Finder Services hotkeys.


This works from the command line, but I don't know how to set up Automator:

https://superuser.com/questions/399899/show-hide-extension-of-a-file-through-os-x-command-line/531941#531941


This answer also gets me almost there:

https://discussions.apple.com/thread/250660690?answerId=251297382022#251297382022


I just don't know how to pass the input file(s) to Automator.

Posted on Oct 22, 2021 12:06 PM

Reply
Question marked as Best reply

Posted on Oct 23, 2021 3:29 AM

You did say file(s), so I have taken my original post and updated the code to handle all selected files in the Finder. Again, tested on macOS 11.6.


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


Similar questions

6 replies
Question marked as Best reply

Oct 23, 2021 3:29 AM in response to VikingOSX

You did say file(s), so I have taken my original post and updated the code to handle all selected files in the Finder. Again, tested on macOS 11.6.


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


Oct 22, 2021 2:17 PM in response to LaNancy

The following Quick Action works just fine to toggle file extensions on and off in the Finder. Tested: Big Sur 11.6.


Code:


use scripting additions

on run {input, parameters}
	
	tell application "Finder"
		if not input is {} then
			set theFile to input as alias
			set ext_status to extension hidden of item theFile
		else
			return
		end if
		
		if ext_status then
			set extension hidden of theFile to false
		else
			set extension hidden of theFile to true
		end if
	end tell
	
	return input
end run


  1. Launch /Applications/Automator, choose New Document, Quick Action, and then click Choose.
  2. Drag and drop the Run AppleScript action from the Utility Library onto the large workflow window.
    1. Remove any boilerplate content from the Run AppleScript action, and then copy/paste the above code into it.
    2. Click the hammer icon in the Run AppleScript action
  3. Configure the top of the Quick Action as you see in this finished example below.
  4. Save the Quick Action, giving it an applicable name such as Extension Toggle.
  5. Quit Automator.


When you right-click on a single file, choose Extension Toggle from the Quick Actions menu on that secondary Finder menu. As this is a toggle tool, if the extension is present on a selected file, then it will be hidden. The second run of this action on the same file will make the extension visible again.


Finished Quick Action:


Oct 23, 2021 1:45 AM in response to LaNancy

Just one gotcha:


If you enable Show all filename extensions in Finder - Preferences - Advanced, it will do exactly that. Attempting to hide/show individual filename extensions (whether by script or by manual selection in the file's info panel) has no result while that preference setting is in effect:



(But you can also script the overall Finder preference if you feel so inclined...)

Oct 23, 2021 2:28 AM in response to LaNancy

This extends the functionality to multiple selections:


on run {theFinderItems}
	repeat with eachItem in theFinderItems
		tell application "Finder" to set extension hidden of eachItem to not extension hidden of eachItem
	end repeat
end run




Selected folders don't get changed, because they don't have name extensions in Finder. And if you select a mixed bunch of files with hidden/not hidden extensions, they will all be swapped to the opposite.


Cheers,


H



How to hide file extension using Automator or Finder Service?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.