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