Tk/Cocoa does not implement -typevariable. The UI controls for choosing the type are missing, and the typevariable is not touched. Under Carbon it worked. Native Cocoa applications like Pages demonstrate, that the same functionality is possible in Cocoa.
See the attached test script and also bug 3588460
Test script failing under Tk/Cocoa
Screen shot from Pages
The API for extension of file dialogs is described here:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSSavePanel_Class/Reference/Reference.html#//apple_ref/occ/instm/NSSavePanel/setAccessoryView:
tkMacOSXDialog.c includes this comment around line 496:
"The -typevariable option is not really supported."
I don't see a class method in NSSavePanel that returns the type of file selected; the closest thing I can find is [URL], which returns a file URL pointer. That doesn't sound like what you are looking for.
I'm not quite clear on the use case for the -typevariable flag: when is such a thing used?
Also, after testing the attached sample script on Lion with both Tk-Cocoa (8.5.13) and Carbon (8.5.3), I do not see the UI component highlighted in the save dialog, and I get this error after closing the dialog: can't read "seltype": no such variable.
I'm a bit lost as to what you are trying to achieve here.
The functionality is explained in TIP242, termed as "Done" for 8.5:
http://www.tcl.tk/cgi-bin/tct/tip/242
You are right, it's also not working under Carbon. But the open panel has it under Carbon. Try:
tk_getOpenFile -typevariable seltype -filetypes {{ASCII *.txt} {Unicode *.txt}}
The use case described there is for example a save dialog which allows to select between different output formats. If you do
tk_getSaveFile -typevariable seltype -filetypes {{ASCII *.txt} {Unicode *.txt}}
on X11 or Windows, after it returns, you can switch on the varable "seltype" which is supposed to contain "ASCII" or "Unicode", according to the user's selection - just like it is possible with Pages. To see the expected behaviour, open the save panel for Pages and switch between "Word" and "iWork" - it also changes the extension from .doc to .pages.
I have browsed through the docs of Apple, it seems there is no simple method to NSSavePanel to achieve this; instead, on has to use the acessory view to insert additional widgets. This question was also asked few times in forums. See e.g.
http://stackoverflow.com/questions/10533517/with-nssavepanel-how-can-the-user-choose-a-specific-file-type-to-save
and the "Custom Save" example
https://developer.apple.com/library/mac/#samplecode/CustomSave/Introduction/Intro.html
The Carbon API (NavServices) supported this functionality more or less out of the box: it allowed you to populate a popup menu with file types without adding a lot of extra code. By contrast, as you've noted, Cocoa's dialogs offer no such built-in support and require accessory views. I suspect this significant extra complexity is why das did not include such support in Tk-Cocoa.
The sample code you pointed me to is not reassuring in terms of its complexity: that's a *lot* of code to add for a single variable flag. Given my limited time, and given that this is extremely non-trivial to implement, I can't make any commitment as to if or when it will be added. If you want to provide a patch, that would be a huge help.
I understand that you are busy with other things. I just want to make the point that this functionality is the only sensible way to make an export dialog for an application which supports multiple file formats. The other options include:
*Switching on the extension - not obvious to the user
*Popping up a second dialog with options - two modal steps
*Different menu entries for each format - impractical for more than 2 file formats
Maybe I'll try to get my hands dirty on this, however, I've no experience with Cocoa, so no guarantee.