Extracting a HIG file name from URL/path

I want to set the title of my window to the name of an opened file, like much applications.

  1. I’m not using NSDocument.
  2. I’ve bound the property gWindowTitle to the window’s title in IB.

This works but seems complicated to me:

There must be something more simple ? :confused:


Use setRepresentedURL: or setRepresentedFilename:.


Both methods set a nice icon on the window’s titlebar but no file name.

setTitleWithRepresentedFilename: is better but is it possible to cut off the extension?

Well yes, you can do it manually as you were earlier. But why?

There’s a standard format and a standard associated behavior for document titles (dimmed icon for dirty docs, ability to drag to Finder, and ability to control-click and see file’s hierarchy, and open from the Finder there). Do you have good reason to potentially annoy the user by doing something different from every other doc-based app?

Cocoa programmers have a saying: Don’t fight the frameworks. It’s usually good advice.

OK, Shane, thank you. I’ll try to remember this.

May the Framework be with you!

Ok Shane,

This is what I did to obtain what I want, without fighting the frameworks and to stay in the Guidelines:

-- NSDictionary and NSFileManager are declared in properties as classes
set theFilePath to |path| of theFileURL as text
set fDic to NSDictionary's dictionaryWithObject_forKey_(1,"NSFileExtensionHidden")
manager's setAttributes_ofItemAtPath_error_(fDic,theFilePath,missing value)

Ex-Toolbox programmers also have a saying: “Where there is a will, there is a way”. :cool:

I don’t think that works if the Finder preference is set to always show extensions.

But it still strikes me as a bit odd: the default behavior is to show the extension, unless the user turns off the extension for the file, and you’re having the app turn it off rather than the user, so they you’re setting their behavior in the Finder as well.

You’re right, Shane, and finally it’s just a detail: many people don’t even notice the extension and what it means (maybe former Windows users can’t live without extensions), and my user remains free to show the extension of its wrapper, and even to ruin its contents if he wants to. :slight_smile:

But this extension affair is the tree hiding the forest, as my problem is only partially solved: I have at last my wrapper, but I can’t tell the finder to use it as a regular folder, open it and writing files into it. Do I have to use Cocoa methods instead of Applescript to do this?


The Finder relies on what’s in the lauchd database, which gets its info from the exported UTI. We’re back to the other thread…

We’re back to the other thread.

And nothing more. XCode 3 doesn’t help me with the Exported UTI.

That thread has all the info you need.