Frustrating... File extensions!

A million times allready (searching bbs) I’ve found how to get the name extension of any file:

tell app "Finder" to get name extension of alias

which, of course, I knew how to do… (not bragging about how smart I am… just pointing that I obviusly need exactly that I don’t know)

Now, how to set an extension… I also figured out, you don’t

set the name extension of alias to "ext" -- as far as I know...


set the name of alias to "FileName.ext" -- if you set the name of alias to "FileName" it won't be a recogniced file type, so you have to add it

So enough intro… all I need now is to know how to hide that extension…
In the Finder Dic, the file class in Files inherits from the item class in Finder Items. Under “item” you should find one of it’s properties: ‘extension hidden boolean’
Well, I could not find the correct use of this.

set name of alias to "FileName.ext" with extension hidden -- eeeeeeeeeeeeeeek, wrong!
set name of alias to name of alias with extension hidden -- eeeeeeeeeeeeeeek, error!
set name of alias to name of alias extension hidden true -- eeeeeeeeeeeeeeek, you idiot!!
set extension hidden of alias to true -- eeeeeeeeeeeeeeek, stack overflow!!!!!!!!!!! (?) I just had to laugh!!

So I’m pretty much out of guesses… Any advice? Thanks a lot!

Model: PowerBook G4 17"
AppleScript: 1.9.3
Browser: Safari 1.3 (v312)
Operating System: Mac OS X (10.3.9)


Unless you want to resort to string manipulations and delimiters, here’s a possible workaround:
If you turn off the Advanced option in the Finder preferences to “Show all file extensions”

tell app "Finder"
set nameWithoutExtension to (displayed name of (selection as alias))
end tell

This may or may not work for you, depending on whether you want you (or your audience) to be able to see the extensions.

Jim Neumann

This works for me (it toggles extension visibility on and off):

set the_file to "path:to:file"
tell application "Finder" to set extension hidden of file the_file to not (get extension hidden of file the_file)


Model: PowerBook 1.25MHz
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)

The Finder preference about showing all file extensions is off, but you might still force your files to show or not show file extensions individually (either that or my Mac is unique… :stuck_out_tongue: ) . Since I’m changing the file extension previously in my script, it’ll show. What you suggested would work if the “Hide Extension” checkbox were to be enabled in the file info window, so that what the user would see on any Finder window would be just “FileName” and not “FileName.ext”. The thing is (BlueFrog, try your suggestion) that if you actually see the extension, the ‘displayed name’ will return “FileName.ext” … and not mentioning that if you by chance selected more than one file in a Finder window your code crashes :confused:

As said, when I save a file (take for example, if you right-click and save image to “Whatever”) It’s saved as .jpg but it’s actually .bmp … not a clue why!! What I do is change the file name and it’s extension. So far so good. Now all I would like to accomplish is to get rid of that $#^@ extension… (call me crazy, I just want to :smiley: ). The thing is I can’t just remove it from the name, since that would turn the file unreconizable! I need to hide it’s extension…

Hope this clarifies… Thanks again!

Sorry, was writing reply when you answered Jonn!! Works perfect!! (is it just me or is this way complicated?)
Anyway, might not be what I expected, but it does it’s job!! Great, thanks a lot!

If you have a variable named thisFile which points to an alias, you can hide the extension simply by saying

tell application "Finder" to set extension hidden of thisFile to true

(Edit: I know that’s essentially the mechanism used by Jon in his post above, but I’m just pointing out that you don’t have to know whether the extension is currently hidden or not in order to set it to be hidden via your code.)