I'm looking for a way, via terminal, to change whether or not a specific file's extension is shown in the Finder, something along the lines of:

$ hideextension ~/music/somesong.mp3

Without having to open Get Info and change the checkbox, as it's massively tedious.

I plan on incorporating it into a script I'm calling via a shortcut using FastScripts. I'd like to try and stay away from GUI scripting as that feels unclean, although any ideas on how to accomplish this are welcome.

  • If it makes any difference, I'm trying to accomplish this on Lion. Mar 12, 2012 at 20:18
  • 1
    Similar to apple.stackexchange.com/questions/114053/…
    – gagarine
    Aug 12, 2022 at 7:30
  • Hey @gagarine ! Looks like this question is a little older and the one you mention didn't exist when this was posted, but thanks for posting some relevant info! specifically the Hazel stuff which doesn't get mentioned in answers here Jan 23, 2023 at 14:03

7 Answers 7


The only real way to change this via GUI is to click Hide extension in the Finder Info window. Checking this changes the com.apple.FinderInfo extended attribute, which you normally can't edit – at least not easily. We can however use a tool to do it for us.

For the below to work, you obviously need to have Show all file extensions unchecked in Finder's preferences.

Through AppleScript

AppleScript offers this functionality with the set extension hidden command. You obviously need an alias to a file object. We can get that, for example, though a dialog. Here's just a minimal working example.

tell application "Finder"
    set some_file to (choose file)
    set extension hidden of some_file to true
end tell

To reverse, just exchange true with false here. The full call is then, for example:

set extension hidden of alias "Macintosh HD:Users:werner:Desktop:file.png" to true

You can run this straight from a script file too (thanks @DanielBeck for the addition):

on run argv
tell application "Finder" to set extension hidden of (POSIX file (first item of argv) as alias) to true
end run

Save this as filename.scpt and run it from the command line with:

osascript filename.scpt targetfile

With the SetFile command

Note: This is deprecated since Xcode 6.

If you have Xcode installed, you will get the SetFile(1) binary, which does exactly what you want (and offers a few more functions related to file attributes):

Hide extension:

SetFile -a E <file>

Show extension again:

SetFile -a e <file>
  • Strictly speaking, it's an alias, not a file. Here's how to use the AppleScript from the command line: on run argv [newline] tell application "Finder" to set extension hidden of (POSIX file (first item of argv) as alias) to true [newline] end run, use as osascript filename.scpt targetfile.
    – Daniel Beck
    Mar 12, 2012 at 21:45
  • 1
    You're right, of course. I added the full AppleScript event. In the future, just go ahead and add anything important to the answer – you're always welcome to.
    – slhck
    Mar 12, 2012 at 21:50
  • 1
    just what I was looking for.. thankfully I have Xcode installed and SetFile did the trick :-)
    – thandasoru
    Oct 2, 2013 at 13:42
  • SetFile is deprecated since Xcode 6. Also the link to manual page has expired. Nov 8, 2018 at 5:25
  • @FranklinYu Thanks for the info. Do you know of a replacement?
    – slhck
    Nov 8, 2018 at 7:19

Thanks slhck for your answer, it helped me do what I wanted.

Since I like shortcuts, I created a "Run Shell Script" Service through Automator:

for f in "$@"
    STATUS=`getFileInfo -ae "$f"`
    if [ $STATUS== 0 ];
        SetFile -a E "$f"
        SetFile -a e "$f"

Then in Finder -> Services Preferences, I added a shortcut to the Service.

Command+Shift+H didn't work for me, and Command+H hides the application. I chose Command+Shift+E.

  • The STATUS= line is missing a back-tick at the end. Also, on my Mac + XCode, the command GetFileInfo has a capital G.
    – bjnord
    Mar 3, 2015 at 1:25

There is one more option if you want to show file extension that is currently hidden: Finder stores this "hide extension" option in com.apple.FinderInfo extended file attribute. You can check it yourself by running this command which lists all extended attributes:

xattr -l /path/to/the/file

So, in order to show the extension, you can remove that attribute:

xattr -d com.apple.FinderInfo /path/to/the/file

But keep in mind that Finder stores other metadata such as tag color in this attribute, so this metadata will be lost. And, since the attribute is binary, you cannot easily modify it.


In order to have only one argument on the command line ($ hideextension ~/music/somesong.mp3), you can make your applescript become a shell script. It is possible to use osascript in the shebang (#!/usr/bin/osascript) like in the following code. To proceed :

  1. Test your applescript code in a .scpt file => toggle_hidden_extension.scpt
  2. When OK, add the shebang (#!/usr/bin/osascript) at the beginning of the file
  3. Export it with file format "text" => toggle_hidden_extension.applescript
  4. Change extension to .sh => toggle_hidden_extension.sh
  5. In Terminal, make it executable :

    chmod u+x toggle_hidden_extension.sh
  6. Now you can run it :

    ./toggle_hidden_extension.sh /path/to/myfile.mp3

So, the code to illustrate:


usage: toggle_hidden_extension.sh file

Test 1 : ./toggle_hidden_extension.sh /Users/boissonnfive/Desktop/file.txt
Test 2 : ./toggle_hidden_extension.sh
Test 3 : ./toggle_hidden_extension.sh 0fdjksl/,3

on run argv
        toggleHiddenExtension(item 1 of argv)
    on error
        return usage()
    end try

    if result then
        return "Extension hidden for " & POSIX path of (item 1 of argv)
        return "Extension revealed for " & (POSIX path of (item 1 of argv))
    end if

end run

on usage()

    return "usage: toggle_hidden_extension.sh file"

end usage

on processArgs(myArgs)

    set item 1 of myArgs to POSIX file (first item of myArgs) as alias

end processArgs

on toggleHiddenExtension(myFile)

    tell application "Finder" to set extension hidden of myFile to not (extension hidden of myFile)

end toggleHiddenExtension

Even if SetFile is deprecated since Xcode 6 it’s still available in XCode 11, so you can expect it to remain in the Command Line Tools for the foreseable future...


$ pkgutil --payload-files /Volumes/Command\ Line\ Developer\ Tools/Command\ Line\ Tools.pkg | grep SetFile

Here is an AppleScript that will work on a finder selection and allow you to unhide the file extensions on all selected files.

tell application "Finder"
    if not (get selection) = {} then
        set theSelection to (selection as alias list)
        display alert "Nothing selected in the Finder." giving up after 10
    end if
end tell

repeat with theFile in theSelection
    tell application "Finder" to set extension hidden of theFile to false
end repeat

You can easily do this in Terminal with the SetFile command:

To hide file extension

SetFile -a E <file>

To show file extension

SetFile -a e <file>

To recursively hide file extensions in a directory and all sub-directories:

(You can change the second * to a particular extension type if needed)

cd <path to directory>
find . -name "*.*" -exec SetFile -a E '{}' \;                          

To recursively show file extensions in a directory and all sub-directories:

(You can change the second * to a particular extension type if needed)

cd <path to directory>
find . -name "*.*" -exec SetFile -a e '{}' \;                          

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .