MacOS – How to use AppleScript to un-hide a file’s extension

applescriptfile extensionsmacos

In Finder, if you right click a file → Get Info, you will see a checkbox in the Name & Extension section that offers users the ability to Hide extension.

If you press Command (⌘)-Shift-3 to take a whole-screen screenshot on your Mac, a screenshot is saved as a .png file. By default, the .png extension for a screenshot is hidden.

Can I change this hide extension status using AppleScript?


If you are curious as to why I'm trying to perform this action in AppleScript, it is because I have a script that involves taking & saving a screenshot, and then naming the file based on the text on the clipboard. And, in this process of renaming the file, Finder no longer recognizes the file as a .png file, so I have to manually change the filename.

Best Answer

Never mind! I found the answer here:

Super User: Show/hide extension of a file through OS X command line

I will delete this question now!

EDIT -

Since some are upvoting this question, I will echo the top answer in the linked question (supplied by @slhck).

A straightforward solution exists, because AppleScript specifically offers a set extension hidden command designed to do exactly what I'm looking for.

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

And that will make the file extension visible!