Show or hide filename extension

Is there a way to automate the show or hide of a filename extension of files in Finder? Manually, I have to open the file info with Cmd + i and check/uncheck the box for "Hide extension". How can I select the file(s) in Finder and use a shortcut to toggle the setting?

Probably this works with some script. What I have tested is the image recognition. That works fine too.

  • ⌘i
  • delay
  • image recognition
  • left click
  • ⌘w

If you want to run the macro with ⌘i, then use the action trigger menubar item instead of ⌘i (in the macro).

You can use applescript for hide/show file extensions. Here are 2 applescripts, one for toggle the visibility of the selected file extension and the other one for always hide the file extension.
Both works fine if you select one item in Finder or more than one.

  1. APPLESCRIPT TOGGLE FILE EXTENSION

tell application "Finder"
try
set n to (count of (selection as alias list))
if n = 0 then
tell application "System Events"
display notification with title "No item selected" subtitle "(Visibility of file extension has not changed)"
end tell
return 0
end if
repeat with x from 1 to n
set itemActual to (item x of (selection as alias list))
if extension hidden of itemActual is false then
set extension hidden of itemActual to true
else
set extension hidden of itemActual to false
end if
end repeat
on error
tell application "System Events"
display notification with title "ERROR" subtitle "Impossible to hide or show the file extension"
return 0
end tell
end try
end tell
return 1

  1. APPLESCRIPT for ONLY HIDE FILE EXTENSION

tell application "Finder"
try
set n to (count of (selection as alias list))
if n = 0 then
tell application "System Events"
display notification with title "No item selected" subtitle "(Visibility of file extension has not changed)"
end tell
return 0
end if
repeat with x from 1 to n
set itemActual to (item x of (selection as alias list))
set extension hidden of itemActual to true
end repeat
on error
tell application "System Events"
display notification with title "ERROR" subtitle "Impossible to hide or show the file extension"
return 0
end tell
end try
end tell
return 1

In BTT, choose "Add New Trigger", select a trigger type, and customize it. Then, choose "Run Apple Script (async in background)" as the action, and paste in your script. Select the files you want to change, and activate the trigger to make the changes automatically.

tell application "Finder"

try

set selectedItems to selection

if selectedItems = {} then error "No items selected"

repeat with selectedItem in selectedItems

set extensionHidden to extension hidden of selectedItem

set extension hidden of selectedItem to not extensionHidden

end repeat

display notification "File extensions have been toggled." with title "Success"

on error errorMessage

display alert "Error" message errorMessage as warning

end try

end tell

Thank you, all! I tried the latter and it works great!

1 Like