Mac Home | Mac FAQ | Mac Plugin | Mac Features | Mac Resources

Maintained by: [email protected]

FAQ Index

  • 1. General
  • 1.1. What are the System requirements for MacTk?
  • 1.2. Where is the on-line documentation for Tcl/Tk?
  • 1.3. What tools are available for developing Tcl applications?
  • 1.4. What commercial apps have been released with Tcl & Tk?
  • 1.5. Is there a mailing list for MacTcl?
  • 1.6. Where are some other sites for information about Tcl & Tk?
  • 2. Running the Shells
  • 2.1. What are the shells provided with macTk?
  • 2.2. Can I get either of the shells to run some code automatically on startup?
  • 2.3. How can I respond to having files dropped on my Wish Application?
  • 2.4. Can I get Wish to do something when I double-click on my Tcl scripts?
  • 3. Adding Commands
  • 3.1. How do I add commands to Tcl or Tk?
  • 3.2. Okay, I wrote my C-based command, now how do I get Tcl to acknowledge its existance?
  • 3.3. What compilers should I use to build my extension?
  • 3.4. What if I don't want to use shared libraries for my extensions?
  • 3.5. How do I add commands to the Tcl Plugin?
  • 3.6. I tried to build MacTk 8.0p2 with CW Pro 2, and got a file float.mac.c not found error, what gives?
  • 4. Files
  • 4.1. How can I get creator and type information about Macintosh files?
  • 4.2. How can I list all the Disks mounted on my Macintosh?
  • 4.3. How can I get access to the standard locations (like the extensions folder, and the Trash) provided on the C side by the FindFolder routine?
  • 5. Menus
  • 5.1. How do I install my own menus into the Macintosh Menubar?
  • 5.2. How do I add pulldowns to a Macintosh Menubar?
  • 5.3. Do I have to make a new menubar for each toplevel?
  • 5.4. Can I install my own items in the Apple and Help menus?
  • 5.5. Can I add Menus to the default Wish menu bar
  • 6. Widgets and Windows
  • 6.1. What is a Widget?
  • 6.2. What are the useful commands for dealing with widgets in Tk?
  • 6.3. What are the useful commands for dealing with Macintosh Windows in Tk?
  • 6.4. How can I change the style of the windows I get with the toplevel command?
  • 6.5. Can I iconify windows on the Mac, like I do in X?
  • 6.6. How do I make a toplevel Macintosh window that has no border decorations?
  • 6.7. How can I intercept a users click in the close box of a toplevel?
  • 7. Resources
  • 7.1. Can I read and write resource information?
  • 7.2. Can I use the Macintosh Standard File Dialogs?
  • 7.3. Great! But I need a resource template to read anything but a TEXT resource!!!
  • 7.4. How can I inspect the resource chain?
  • 7.5. How can I add cursors to Tk?
  • 7.6. Can I play 'snd ' resources in MacTk
  • 7.7. Can I use the standard mac system icons, like the note, caution, or folder and document icons?
  • 7.8. Can I use my own ICON and cicn resources in Tk?
  • 8. AppleScript
  • 8.1. Can I use AppleScript to communicate with a Tk Application?
  • 8.2. Can Tk communicate with other applications on the Macintosh?
  • 8.3. How can I use scripts that I have written in the Script Editor in MacTk?
  • 9. Packaging Applications
  • 9.1. How do I turn my script into a double-clickable app?
  • 9.2. How do I set the target Shell that the Drag & Drop Tclets app will clone for my new application?
  • 9.3. How can I deliver an application to a user who doesn't already have Tcl & Tk?
  • 9.4. Is there a Standard place to put extension shared libraries and Tcl code?
  • 9.5. How can I give my Tcl Application a snazzy custom icon?
  • 9.6. Should I plaster the Tcl Feather all over my app?
  • 9.7. I have a double-clickable application, but the console window still comes up. How do I get rid of it?
  • 9.8. I have hidden the console window in my Application, and now for debugging purposes, I would like to get it back. Can I do that?
  • 9.9. How can I replace the Tk "About..." box with my own custom about box?
  • 9.10. What is the env array, and can I use it on the Macintosh?
  • 10. For X-Users
  • 10.1. Why can't I put the focus on a non-foreground window?
  • 10.2. Why can't I change the color of one of the built-in cursors?
  • 11. Cross-Platform Issues
  • 11.1. How do I know what platform I am running on?
  • 11.2. I have some bindings in my code that rely on the other two mouse buttons. How can I simulate these events on the Mac
  • 12. Esoterica
  • 12.1. How can I make an interface between MacTk and MacPerl?
  • 13. Limitations & Known Bugs
  • 13.1. How can I find out what the color depth of the monitor displaying a window is?
  • 13.2. Under MacOS 8, changing the background color of a button has no effect.
  • 13.3. I have a binding to <Command-v> in my text widget, but the binding never fires. How come?
  • 13.4. Can I Print from a Tk Application
  • 13.5. Can I access the serial port on the Mac?
  • 13.6. Does MacTk support PICT image types?
  • 13.7. There are some pixels of grey that peek out from around the corners of the rounded Macintosh buttons
  • 13.8. If I am in a loop processing Tcl code, even though I call "update idletasks" I cannot change the cursor, and the pointer position is not updated
  • 13.9. If I try to destroy a menubutton in its menu's -command, I get an error. This works on UNIX
  • 13.10. Postcommand on pulldown menus doesn't seem to work
  • 13.11. Can I do Drag and Drop from a Tk application?
  • 13.12. I have mounted two volumes with the same name, can I get to both of them?
  • 1. General

    1.1. What are the System requirements for MacTk?
    MacTk requires System 7 or greater. It will run on 68K or PPC Macs. To run Tk usefully you need 4 Meg of RAM for the application. The 68K version requires the CFM-68K Enabler extension. This extension is contained in the MacTk installation.

    1.2. Where is the on-line documentation for Tcl/Tk?
    In the Tcl/Tk distribution, there is a folder called "HTML Docs". The documentation for Tcl and Tk are in there, in HTML format. If you look in the tcl8.0 folder of this folder, there is a file called "contents.html" which is an index of all the commands & the API for Tcl. Ditto for the tk8.0 folder.

    1.3. What tools are available for developing Tcl applications?
    For building GUI's with Tk, there are several tools listed under GUI Builders.

    For writing your Tcl scripts, I suggest the fine code editor Alpha. The official home page for Alpha is: Alpha . Alpha has always had a good Tcl editing mode, and the 7.0 version has incorporated many of Vince Darley's improvements which has made it even better. Plus, once you know a little Tcl, you can hack at Alpha as well!

    For building your own extensions, currently only CodeWarrior is supported. I suggest getting one of the Pro varieties, since the IDE is significantly improved, and the ANSI C libraries are better.

    1.4. What commercial apps have been released with Tcl & Tk?
    1. The Shaman Update Server - Shaman Corporation
      2415 3rd Street, Suite 231
      San Francisco, CA 94107
      (415) 241-9952
      Shaman_Corp.

    2. Torque Traffic
      Torque Systems, Inc.
      625 Second St., Suite 211
      San Francisco, CA 94107
      (415) 543-6555

    3. Teamwave Workplace
      Teamwave Software Ltd.
      100 Discovery Place One
      3553-31 Street N.W.
      Calgary, Alberta
      Canada T2L 2K7
      Teawave

    1.5. Is there a mailing list for MacTcl?
    Yes, go to the Tcl project at SourceForge to join the list.

    1.6. Where are some other sites for information about Tcl & Tk?
    There's lots of resources available. Check the Tcl Resource Center

    2. Running the Shells

    2.1. What are the shells provided with macTk?
    There are three applications provided with Mac Tk:

    2.2. Can I get either of the shells to run some code automatically on startup?
    Yes. Fire up ResEdit, and add a TEXT resource to the shell you want to modify. Name the resource "tclshrc", the number is not important. Then paste you Tcl script into this resource. This script will then get run on startup.

    2.3. How can I respond to having files dropped on my Wish Application?
    Create a tcl procedure called tkOpenDocument which takes the args keyword for its argument. When a file or files are dropped on your application, this procedure will be run, recieving a list of the files dropped on it in the args variable. So for instance:

    proc tkOpenDocument {args} {
        foreach elem $args {
            puts {Ow! Quit It}
        }
    }
    

    2.4. Can I get Wish to do something when I double-click on my Tcl scripts?
    Yes. You have to do two things:

    1. Add a proc called tkOpenDocument to the wish application in such a way that it is loaded at startup. The best way to do this is to add a TEXT resource to the Wish application named "tclshrc", and define the proc there. This proc will be passed the list of files that were double-clicked on.
    2. Change the creator of your tcl scripts to "WIsH".

    There are some dangers to this approach, however. If you double-click on one script to start it up, and then double-click on another, the second script will get sourced into the context of the first script, which may not be what you want.

    You can partially solve this problem by creating a new interpreter for each script you source in, and sourcing the script in that interpreter. This is not as easy as it seems, however, since you have to be sure to load Tk into the new interpreter, and mask the exit command so that one script doesn't kill another... It is probably a better idea to use the "Drag & Drop Tclets" application to create Double-Clickable Tcl applications. After all, the Wish shell is only 80k...

    3. Adding Commands

    3.1. How do I add commands to Tcl or Tk?
    There are two ways to do this:

    1. If you can implement the command in Tcl, then you just write a new tcl proc, using the proc command. See the proc.n.html file for more details.
    2. If the guts of your command are implemented in C, you need to use the Tcl C API for creating commands. Look at the CrtCommand.3.html and CrtObjCmd.3.html doc pages for more details. There is also an example of how to do all this in the helpful file C_API .

    3.2. Okay, I wrote my C-based command, now how do I get Tcl to acknowledge its existance?
    The best way to do this is to package your new command into a shared library, and then either load it directly into Tcl using the "load" command, or set it up as a Tcl package, and use the "package require" mechanism.

    Look at the project file in the example_tcl_extension to see how to configure CodeWarrior to build the shared library. Look at the last bit of the example.r file to see how to put in a pkgIndex file so you can use the "package require" command to load your library. Look at the example.c file to see how to write the _Init routine that will be run when your library is loaded.

    3.3. What compilers should I use to build my extension?
    At present we only support CodeWarrior. The Example extension has a project file for use with CodeWarrior Pro 1 or later.

    3.4. What if I don't want to use shared libraries for my extensions?
    Sometimes it is more convenient to have your whole application in just one file. In that case you want to build the Static version of Wish, with your commands added. So here's what you do:

    1. In the TkShells.pi project, make a new target which is a clone of either "ppc*Simple Tk" or "68K*Simple Tk", depending on which architecture you want to target.
    2. Add the files that implement your new command to the project, and any other libraries you may need.
    3. Make a copy of the tkMacAppInit.c file , and edit the Tcl_AppInit function, adding the init procedure for your package. There is a commented-out example showing you what to add. Search for Mod_Init and you will see it.
    4. Build your new shell.

    3.5. How do I add commands to the Tcl Plugin?
    At present, the only way to add commands to the Mac Tcl Plugin is to bind them in statically. This is basically the same as the procedure described in the preceeding question. To understand the differences, you have to know a little about how the plugin works. There is a main Tcl interpreter running in the plugin that sets up child interpreters in which the actual Tclets are run. These interpreters are "safe" interpreters, that is, they restrict the commands that they will allow, so that a foreign Tclet cannot harm your system. You want to load your extra commands into the child interpreters, not in the Main interpreter. So, you need to do several things.

    1. You have to provide a Foo_SafeInit entry point as well as an ordinary Foo_Init entry point in your extension code, since a "safe" interpreter will only run the SafeInit function. Don't just change the name of the function, from Foo_Init to Foo_SafeInit, however. You have to think a bit about which commands in your package really are safe...
    2. You have to tell Tcl that you have provided another package, so that Tcl will know to load your package from the Tcl Plugin library, rather than from a shared library on the disk (which will fail at present). To do this, just add:

      Tcl_StaticPackage(interp,"Foo",Foo_Init, Foo_SafeInit);

      to the Plug_Init function which is in nptcl.c.

    3. You do not have to run the Foo_SafeInit function in Plug_Init, since, after all, you want to add your commands to child interpreter, not to the main interpreter. To do this, put:

      load {} Foo

      in your Tclet code somewhere.

    3.6. I tried to build MacTk 8.0p2 with CW Pro 2, and got a file float.mac.c not found error, what gives?
    Between CW Pro 1 and 2, Metrowerks merged all the platform specific float.*.c files into one, called float.c. So you have to open the project "tcl8.1:mac:MacTcl MSL.pi", remove float.mac.c, and put in its place "{Compiler}:Metrowerks Standard Library:MSL C:MSL Common:Source:float.c". Then everything will build.

    4. Files

    4.1. How can I get creator and type information about Macintosh files?
    The "file attributes" command will give you this information:

    %file attributes "Wish 8.0p2"  -creator WIsH -hidden 0 -readonly 0 -type APPL
    

    The same command will allow you to set the creator or type:

    % file attributes "foo.html" -creator "MOSS"
    

    will make the file foo.html a Netscape file.

    4.2. How can I list all the Disks mounted on my Macintosh?
    The command "file volumes" will list all the volumes on your Macintosh.

    4.3. How can I get access to the standard locations (like the extensions folder, and the Trash) provided on the C side by the FindFolder routine?
    This is one of the main uses of the env array on the Mac. So for instance to find the Desktop Folder of the Startup disk, look at $env(DESK_FOLDER). Currently, we only support the System 7.6 FindFolder defines, but in the future we will include the new ones that were added in 8.0.

    5. Menus

    5.1. How do I install my own menus into the Macintosh Menubar?
    Each toplevel has a menu associated with it. You set it with the -menu option of the toplevel thusly:

        menu .mbar -tearoff 0
        . configure -menu .mbar
    

    This menu is displayed in the Main Macintosh menubar whenever the toplevel that owns it (in this example .) is in the foreground.

    5.2. How do I add pulldowns to a Macintosh Menubar?
    To make the menu entries in the menubar, you add cascade entries to the menu you have installed for that toplevel. Each cascade entry will show up as a seperate pulldown of the main menu bar. So the following code installs a pulldown called "File" with "New", "Open...", "Save" and "Quit" entries into the menubar .mbar:

        .mbar add cascade -label File -menu .mbar.file
        menu .mbar.file -tearoff 0
        .mbar.file add command -label New  -accelerator Command-N -command "NewDoc"
        .mbar.file add command -label Open...  -accelerator Command-O -command "OpenFile"
        .mbar.file add command -label Close  -accelerator Command-W -command "CloseDoc"
        .mbar.file add separator
        .mbar.file add command -label Save  -accelerator Command-S -command "SaveDoc"
        .mbar.file add command -label "Save As..." -command "SaveDocAs"
        .mbar.file add separator
        .mbar.file add command -label Quit  -accelerator Command-Q -command exit 
    

    5.3. Do I have to make a new menubar for each toplevel?
    No. By default all toplevels inherit the menubar of their parent. Since everything is a child of ".", this means that changing the menubar for "." propagates that change to all the toplevels in your application. So if you create a new toplevel with:

        toplevel .top
    

    then ".top" will display the same menubar as ".". If later on, you make a new menubar for .top, and then create a child of .top thusly:

        .top configure -menu .top.mbar
        toplevel .top.child
    

    Then . will have its original menubar, and .top AND .top.child will share the menubar given by .top.mbar.

    5.4. Can I install my own items in the Apple and Help menus?
    Yes. To install an entry in the Apple menu, you need to create a special cascade entry for your menubar. If the menubar you are using is called ".mbar", then create a cascade menu entry, whose menu is ".mbar.apple":

        .mbar add cascade -menu .mbar.apple
    

    Then all the menu entries that you add to .mbar.apple will appear under the Apple Menu pulldown, above the separator bar that holds the DRVR entries.

    To install entries in the help menu, create a cascade entry whose menu is .mbar.help:

        .mbar add cascade -menu .mbar.help
    

    and the entries in this menu will appear below the separator that follows the "Show Balloons" entry.

    5.5. Can I add Menus to the default Wish menu bar
    No. This menubar is a simple Macintosh menubar, and cannot be modified. However, the only substantial code in the default menu, namely that which implements the Cut, Copy, Paste and Clear entries, is easily duplicated using the Tk virtual event generation. Just use:

        menu .mbar -tearoff 0
        .mbar add cascade -menu .mbar.file -label File
        .mbar add cascade -menu .mbar.edit -label Edit
        menu .mbar.edit -tearoff 0
        .mbar.edit add command -label Cut -accel Command-X -command {
            event generate [focus] <<Cut>>
        }
        .mbar.edit add command -label Copy -accel Command-C -command {
            event generate [focus] <<Copy>>
        }
        .mbar.edit add command -label Paste -accel Command-V -command {
            event generate [focus] <<Paste>>
        }
        .mbar.edit add command -label Clear -command {
            event generate [focus] <<Clear>>
        }
    

    6. Widgets and Windows

    6.1. What is a Widget?
    In Tk "widget" is the name for any distinct UI element. A widget has a command to create instances of the widget, and when created, there is an access command to send messages to the widget. The standard Macintosh windows are widgets (created by the toplevel command). Also, all the normal Macintosh controls, like buttons, are widgets in Tk.

    6.2. What are the useful commands for dealing with widgets in Tk?

    6.3. What are the useful commands for dealing with Macintosh Windows in Tk?

    6.4. How can I change the style of the windows I get with the toplevel command?
    There is an unsupported command that allows you to do this. In the future, we will provide a cross-platform version of the command, but for the present (Tk 8.0) do:

        toplevel .t1; unsupported1 style .t1 floatProc
    

    The available styles are: documentProc, dBoxProc, plainDBox, altDBoxProc, movableDBoxProc, zoomDocProc, rDocProc, floatProc, floatZoomProc, floatSideProc, or floatSideZoomProc.

    NB at present Tk does not properly support floating windows. They are the REAL foreground window so you cannot have a palette AND a document window concurrently active. This will be fixed in a future release.

    6.5. Can I iconify windows on the Mac, like I do in X?
    If you have Tk 8.0 AND MacOS 8.0 (or the Appearance Manager extension when Apple releases the final version of the SDK) then "wm iconify" will WindowShade the window. Otherwise, it is equivalent to "wm withdraw", which is probably not what you intended. So it is not a good idea to use this command. In any case, it is not a very Mac-like thing to do...

    6.6. How do I make a toplevel Macintosh window that has no border decorations?
    This is done through the following command:

        toplevel .t1; wm overrideredirect .t1 1
    

    NB. The second part of the example (the wm blahblahblah part) has to be run BEFORE the window is mapped.

    6.7. How can I intercept a users click in the close box of a toplevel?
    Give the following Magic invocation:

        wm protocol . WM_DELETE_WINDOW { 
            puts foo
        }
    

    This will write foo to the console every time the user clicks in the close box. Note that if you intercept the click in the close box, Tk will no longer delete the window for you. There is no problem with keeping the window around, but if you want to get rid of it, you must do:

        wm protocol . WM_DELETE_WINDOW { doCleanup; destroy .}
    

    7. Resources

    7.1. Can I read and write resource information?
    Yes. Tcl has a "resource" command for this purpose. It will allow you to open , read from and write to the resource fork of any Macintosh file. For more details, see the resource.n.html document in the "HTML Docs" folder.

    7.2. Can I use the Macintosh Standard File Dialogs?
    Yes, the commands tk_getOpenFile and tk_getSaveFile will put up that standard Macintosh get file and save file dialogs.

    7.3. Great! But I need a resource template to read anything but a TEXT resource!!!
    Yes, that is right. You can, however, write your own resource templates using the "binary" command. For instance, to read an STR# resource, you would use:

    #-------------------------------------------------------------------
    # readStrList --
    #
    # Read the STR# resource in resource specified in args, which contains
    # a resource specification (name or id) and optionally a resource file
    # token.
    #
    # Result:
    #     A list of the strings found
    #
    #-------------------------------------------------------------------
    proc readStrList {args} {
        if {[llength $args] == 1} {
            set strList [resource read "STR#" [lindex $args 0]]
        } elseif {[llength $args] == 2} {
            set strList [resource read "STR#" [lindex $args 0] [lindex $args 1]]
        } else {
            error "Wrong # of args, should be \"resource ?resourceFile?\""
        }
        binary scan $strList S numStrs
        if {$numStrs == 0} {
             return
        }
     
        set pointer 2
     
        for {set i 0} {$i < $numStrs} {incr i} {
            binary scan $strList x${pointer}c numChars
            set $numChars [expr ( $numChars + 0x100 ) % 0x100]
            incr pointer
            binary scan $strList x${pointer}a$numChars string
            lappend result $string
            incr pointer $numChars
        }
        return $result
    
    }
    

    To find out the binary format of a resource, just look it up in the .r files in the Apple Rez headers.

    7.4. How can I inspect the resource chain?
    The command "resource list" returns the list of currently open resource files.

    7.5. How can I add cursors to Tk?
    You add either CURS or crsr (mono & color respectively) cursor resources either to the Wish application, or to the resource fork of any file whose resource fork you have open. Give the resources some distinct name, and then pass that name to the -cursor option for any widget. Note, if you have both color and mono cursors, Tk will use the color version.

    NB Adding cursors will introduce a System specific code to your app. The Mac version of Tk does not support the "@filename maskname" syntax for cursor specification that Unix does.

    7.6. Can I play 'snd ' resources in MacTk
    Yes. There is a "beep" command, supported only on the Macintosh, that will allow you to play any snd resource which is in the resource chain. You can list the available snd resources with:

    % beep -list
    {Simple Beep} Sosumi {Wild Eep} Indigo Droplet Quack Basil
    {Bend Me} {Blue Dust} Bye! Dewdrop Jacaranda Natal {Ryan's Hope} Sheet
    Solly Transvaal {16-bit Geiger} Stravinsky-short {8-bit Jaaazzz Beep}
    {16-bit Molitov}
    

    and play a sound using:

    % beep {16-bit Geiger}
    

    You can even set the volume with:

    %beep -volume 0x01000100 {16-bit Geiger}
    

    where the -volume is the low and high words of a long, corresponding to the right and left speaker volumes. 0x0100 is full on, 0x000 is off.

    7.7. Can I use the standard mac system icons, like the note, caution, or folder and document icons?
    Yes, there are a bunch of the standard mac icons that you can pass to the -bitmap argument of buttons, etc, and use in canvas items. The full list is given in the GetBitmap.3.html manual page at the beginning of the Description section.

    7.8. Can I use my own ICON and cicn resources in Tk?
    Yes, you can use them in the -bitmap option of any widget that supports this option. Here's what you do. Create a ICON or cicn option, and put it in some file on the resource chain of your application. This means put it into the wish shell, or into any loaded shared library, or any file you open with the "resource open" command. Give the resource a name, like "myIncrediblyNeatIcon", then do:

    button .b1 -bitmap myIncrediblyNeatIcon
    

    Note that you are cheating a bit here, since you can use cicn's, which will be rendered in color, although traditionally bitmaps are two-tone. However, the -foreground and -background options will do weird things in this case. It is best to leave them unset.

    NB. You CANNOT use these ICON and cicn items in the bitmap image type. So for now, if you want to use an ICON or cicn resource on a canvas, you need to make a label widget, put the bitmap on that, and embed the label in the canvas.

    8. AppleScript

    8.1. Can I use AppleScript to communicate with a Tk Application?
    Yes. Tk supports the "open" and "close" AppleEvents, and more usefully a "do script" Apple Event. So from AppleScript, you can do:

    tell application "Wish 8.0p2" to do script "puts Hello"
    

    8.2. Can Tk communicate with other applications on the Macintosh?
    Tcl can send AppleScript commands to any OSA compatible application on the Macintosh using the Tclapplescript extension. This extension is shipped with Tcl & Tk. To use it, you must bring in the Tclapplescript package, with the command:

    package require Tclapplescript
    

    After you have loaded the Tclapplescript package, you can use the AppleScript command to execute scripts, for instance:

    button .b1 -text "Launch Navigator" -command {
        AppleScript execute { 
            open application "Netscape Navigator 4.03"
        }
    }
    

    For more information see the AppleScript.html page in the tcl8.0 folder of the HTML Docs.

    8.3. How can I use scripts that I have written in the Script Editor in MacTk?
    Use the AppleScript load command to load the script, and then the run subcommand to run it:

    set myScript [AppleScript load myAppleScriptFile]
    button .b1 -text "Run Script"  -command [list AppleScript run $myScript]
    

    9. Packaging Applications

    9.1. How do I turn my script into a double-clickable app?
    Just drop your main script onto the Drag & Drop Tclets app that comes with the MacTk distribution. It will prompt you for an app name, and you are good to go. If your app has more than one script file, than drop the bootstrap script on the Drag & Drop Tclets app, and include the others in the resource fork of your app. See question 9.4 for more details

    9.2. How do I set the target Shell that the Drag & Drop Tclets app will clone for my new application?
    Double-click on the Drag & Drop Tclets app, and choose "File->Select Wish Stub"

    9.3. How can I deliver an application to a user who doesn't already have Tcl & Tk?
    You have two choices here.
    1. You can build a static version of Wish, select that as the clone app for the Drag & Drop Tclets (see question 9.2 for details on how to do this) and ship that. This method is safe, in that you know what version of Tcl & Tk you are going to get. On the other hand, you can't share the libraries with other Tk apps, and so can't take advantage of the Memory savings afforded if Virtual Memory is turned on.
    2. You are welcome to ship the Tcl & Tk libraries with you app. As with all shared libraries on the Mac, you can either install the libraries in your own application folder, or in the Extensions Folder. If you choose the latter, then please install them in the Tool Command Languages folder under the Extensions folder. There is a Loc file in the example_shared_library.sea.hqx that you can use with Stuffit InstallerMaker to target this folder. Also make sure you check "Install only if newer" for your libraries.

    9.4. Is there a Standard place to put extension shared libraries and Tcl code?
    Yes. On the Macintosh, the standard library location is the "Tool Command Language" folder within the Extensions folder. To help you build installers, there is a "Loc" file in the example shared library builder that you can put in the Locations folder of Stuffit InstallerMaker. It will add the Tool Command Language folder as an install destination.

    You can install your shared libraries here. If your shared library registers a package, then you can also put a TEXT resource named "pkgIndex" in the file to register the package, and it will be found by Tcl. See the pkgindex resource in the Tclapplescript.shlb library for an example.

    As for your scripts, you have three choices.

    1. If your scripts accompany a shared library, it is most convenient to use the package mechanism within the shared library. Put the scripts in TEXT resources in the shared library. Also include a pkgIndex TEXT resource which has a line of the form:

      package ifneeded myPkg 1.0 [list source -rsrc myPkg.tcl]
      

      Note that you should also have a package ifneeded statement for the shared library as well. See the package.n.html doc in the Tcl8.0 folder of the HTML Docs for more details.

    2. If you are distributing a set of scripts that others might wish to use, or that you might use in more than one Tk application, it is best to use a practice which mirrors what is done on UNIX and Windows. Put the scripts in a sub-folder below the Tool Command Language folder, with some name that is unique to your package. Then you can use the package mechanism but this time using a pkgIndex.tcl file that contains the package ifneeded statements. See the package.n.html doc for more information. The "Tool Command Language" folder will be on the auto_path and the package path, so your packages will always be found if you put them here.
    3. Finally, if your scripts are just some auxillary files that you will use in just one application, then put them in TEXT resources in the Wish shell, and then source them in in your main script with:

      source -rsrc HelperScript.tcl
      

      As of Tcl8.0, the autoloading mechanism does not support the resource fork of applications, so you have to source the files in by hand.

    9.5. How can I give my Tcl Application a snazzy custom icon?
    This is a general Macintosh question, but here goes:
    1. Using ResEdit, add the Icon resources to your Wish Shell, giving them the resource ID -16455
    2. Get the file info (in ResEdit this is in File->Get Info For File), and check the Has Custom Icon bit
    Sometimes you have to close and reopen the window containing the icon to see the change.

    9.6. Should I plaster the Tcl Feather all over my app?
    Yes, yes, yes!!! You could even do like KPT and have the power-user parts of your interface appear magically out from under the feather...

    Seriously, the Tcl Feather is free for you to use. Some nice GIF versions of it ship in tk8.0:library:images folder in the source distribution. The more visibility Tcl has, the more we can justify expending resources developing it.

    9.7. I have a double-clickable application, but the console window still comes up. How do I get rid of it?
    There is an undocumented but relatively stable set of commands that Tk uses internally to manage the console window. You can use them to. The one you want is:"console hide"

    9.8. I have hidden the console window in my Application, and now for debugging purposes, I would like to get it back. Can I do that?
    Yes. The best way to do this is to bind some uncommon event to the "console show" command. For instance, do:

    bind all <Control-Option-ButtonPress> {console show}
    

    9.9. How can I replace the Tk "About..." box with my own custom about box?
    The best way to do this is to override the Standard MacTk menubar (which you will have to do in any App of substance anyway), and add a cascade menu called .mbar.apple to the menubar. Here ".mbar" is a placeholder for the name of your main menubar widget.

    9.10. What is the env array, and can I use it on the Macintosh?
    The env array, for those who are not UNIX hackers, is a way to set system level variables that an application can read and use. It is often used when software is installed to point it to helper files.

    For instance, if your installer puts all the tcl script files for your project in some location on the hard drive, you can then define an environment variable MY_SCRIPT_FOLDER, and add this to Tcl's auto_path with:

    if {[info exists env(MY_SCRIPT_FOLDER)]} {
       lappend auto_path $env(MY_SCRIPT_FOLDER)
    }
    

    That way, Wish will find all your files.

    On the Macintosh, this is not always necessary, since you can put the scripts right in the resource fork of the application. However, if you have a large number of scripts that are used in many applications, this still might be a useful model.

    So, how do you set the env array on the Macintosh. Simple... There is a resource of type STR# and name "Tcl Environment Variables" in the Wish application. To define a new environment variable, just add another string to this list. The form of the string is

    ENVIRONMENT_VARIABLE_NAME=value
    

    Next time you start up Wish, there will be an entry in env, so you get:

    %set env(ENVIRONMENT_VARIABLE_NAME)
    value
    

    Since you can edit resources in Tcl using a combination of the resource and binary commands, you can add these resources from Tcl,. So you could write a Tcl -based installer that would set up the environment variables for the installation!

    10. For X-Users

    10.1. Why can't I put the focus on a non-foreground window?
    This is just not done on the Mac. The foreground window is the only one that should receive keystrokes. The only exception to this rule in the Macintosh interface is floating palettes.

    10.2. Why can't I change the color of one of the built-in cursors?
    You can, but not in the easy way that X allows. The problem is that on the Mac cursors are built in resources. If you want a color cursor, you are expected to make a colored cursor resource. However, there is a workaround (read gross hack...). If you need a cursor "right_ptr red blue", then just create a Mac cursor (resource of type 'crsr') with the right colors, name the resource "right_ptr red blue" and it will work...

    11. Cross-Platform Issues

    11.1. How do I know what platform I am running on?
    There is a Tcl global variable called tcl_platform that contains this information:

    % parray tcl_platform
    tcl_platform(byteOrder) = bigEndian
    tcl_platform(machine) = ppc
    tcl_platform(os) = MacOS
    tcl_platform(osVersion) = 8.0
    tcl_platform(platform) = macintosh

    11.2. I have some bindings in my code that rely on the other two mouse buttons. How can I simulate these events on the Mac
    There are two ways to do this. The cleanest way to is to make a set of abstract button events, <<LeftMousePress>>, <<CenterMousePress>>, and <<RightMousePress>>, say, and use these everywhere in your code. Then somewhere at startup, use the "event add" command to bind <<LeftMousePress>> to ButtonPress-1, and on Unix bind <<CenterMousePress>> to <ButtonPress-2>, but on the Mac, bind it to <Control-ButtonPress-1>, or something else that you are not using...

    The second way is to dispatch your own ButtonPress-2,3 events, with something like:

    bind all <Control-ButtonPress-1> {event generate %W <ButtonPress-2> \ 
        -x %x -y %y -rootx %X -rooty %Y -button 2 -time %t}

    You do have to populate all the detail fields of the event that you are likely to use in your bindings, as this example demonstrates.

    12. Esoterica

    12.1. How can I make an interface between MacTk and MacPerl?
    There are two ways to do this. The traditional way, on UNIX, is to open up a socket connection between Perl and Tk, and to send scripts back and forth on this socket. This will work fine on the Mac as well. The other option is to send "do script" AppleEvents back and forth, although this is likely to be somewhat sluggish.

    13. Limitations & Known Bugs

    13.1. How can I find out what the color depth of the monitor displaying a window is?
    You can't, sorry... At present, Tk fools itself into thinking it is always on a True Color monitor, and lets Quickdraw do the reductions. This assumption needs to get decoupled from the information it maintains about the monitor itself, which will be done in a future release.

    13.2. Under MacOS 8, changing the background color of a button has no effect.
    There are two issues here. One is that for regular buttons, and for the indicators of checkbuttons and radiobuttons, there is no way to set the background color. This is a price you pay to use the native widgets. However, if you really need to color the buttons, then have your users turn off System-wide Platinum Appearance in the Appearance control panel.

    The other is that for radiobuttons and checkbuttons, in MacTk8.0p2 you can also not set the background behind the text for the button. This is possible, and is available in the patch file: MacTk-8.0-appearancePatch.sit.hqx. This is just a source patch, you have to rebuild MacTk to use the changes. NB, if you adopt this patch, then the trick of turning off the System-wide Platinum Appearance will no longer work.

    13.3. I have a binding to <Command-v> in my text widget, but the binding never fires. How come?
    Make sure that you con't have a Command-v menu equivalent. On the Mac, the menu code intercepts the keystrokes fo rmenu equivalents, and doesn't propagate the key event back to the focus window.

    13.4. Can I Print from a Tk Application
    This is high on our list of priorities, but we have not implemented it yet. If you really need this capability, and are interested in putting some effort into coming up with a solution yourself, be sure to contact Mark Roseman Roseman who has done some preliminary work on printing already.

    13.5. Can I access the serial port on the Mac?
    Not as of Tcl/Tk8.0. However, Tcl has a very nice extensible channel driver architecture, and it would be an excellent project for someone to provide a driver for the Macintosh serial port.

    13.6. Does MacTk support PICT image types?
    No. This is high on my list of things to fix, but the whole image subsystem needs overhauling, so it may need to wait for that. However, the image reader is extensible, so if some kind soul in the community wants to provide a PICT reader...

    13.7. There are some pixels of grey that peek out from around the corners of the rounded Macintosh buttons
    The color of these pixels is controlled by the -background option.

    This is really a bug; it makes more sense to use the -highlightbackground color for these few pixels. After all, on UNIX, if you set a background on a containing frame, you have to set the -highlightbackground to the frame's background color or you will get these ugly light grey rings around most of your widgets...

    This will be fixed in a future version.

    13.8. If I am in a loop processing Tcl code, even though I call "update idletasks" I cannot change the cursor, and the pointer position is not updated
    That is right. On the Mac, cursor changes and polling for Mouse position are all done when new events are processed (which does not happen in "update idletasks").

    For now, it is probably better to use plain "update" on the Mac, since otherwise the user cannot even put your application in the background. The only down side with update is that button presses et.c will be processed, so you have to disable the buttons that you don't want activated.

    13.9. If I try to destroy a menubutton in its menu's -command, I get an error. This works on UNIX
    This is a bug in Tk8.0. The simple workaround it to put the menu destruction in an "after idle" wrapper, so do:

      set menu [tk_optionMenu .m foo DELETE]
      pack .m
      $menu entryconfigure 0 -command "after idle {destroy .m}"
    

    13.10. Postcommand on pulldown menus doesn't seem to work
    Yes, that is right, this is broken in Tk8.0.

    13.11. Can I do Drag and Drop from a Tk application?
    This is another thing that is high on our list of enhancments for Tcl & Tk, but it is not done yet.

    13.12. I have mounted two volumes with the same name, can I get to both of them?
    No. Currently you can only access the first one in the "file volumes" list.