[[This page is large and jumbled enough to be a good candidate for refactorization.]] http://www.apple.com/macosx/ is the latest operating system from Apple, which has BSD [Unix] (approximately) as its underlying core, and a very nice GUI on top of it, known informally as "Aqua". Apple itself seems to be consistent in punctuating the label as "[Mac OS X]". ON Mac OS X [Tk] can be built in three versions; '''Cocoa''' (current Apple API), '''Carbon''' (deprecated Apple API), and '''X11'''. Carbon and Cocoa versions runs natively on Mac OS X, using an Aqua look and feel, which is the focus of this page. The '''X11''' version has a more plain interface, requires the installation of some X11 server, but has better performance than the other two. OS X [Tk] is - as of 2012 - in a poor state. Apple's legacy API, '''Carbon''' is being deprecated, but it's replacement, Tk '''Cocoa''', has many non-trivial bugs, especially concerning the event loop, and it is largely unsuitable for complicated Tk projects. Moreover, these bugs have proved hard to fix, and there is currently no prospect of them being resolved. ''The rest of this page is somewhat outdated.'' http://tktoolkit.cvs.sourceforge.net/viewvc/*checkout*/tktoolkit/tk/macosx/README is the URL to the tk/macosx/README file, which was, according to [Daniel Steffen], at some point ''"probably the most complete reference"'' for OS X specific info/features of Tcl and TkAqua. [Daniel Steffen] has a very extensive [Batteries Included] release available: [TclTkAquaBI] (superset of [ActiveTcl] on other platforms). [Alphatk] used to be bundled with Tcl, Tk, but now embeds them. [ActiveState] supports Mac OS X in their ActiveTcl distribution since at least 8.4.13 (see [http://www.activestate.com/Products/ActiveTcl/]). Wish comes as an application (Wish.app) and two frameworks: Tcl.framework, Tk.framework. These must be installed in /Library/Frameworks or ~/Library/Frameworks. There is also a binary distribution "Wish And Go : TclTk for Mac OS X 10.2 Jaguar". This provides a Wish Shell with the Tcl and Tk frameworks and a number of popular extensions all embedded within itself. This stand-alone application is easy-to-install and use, but also provides a good foundation for [Building Stand-Alone Tcl/Tk Applications under Mac OS X]. It is available from http://simulistics.com/tcltk/ "Wish And Go" is intended particularly for users of Mac OS X 10.2 Jaguar, but also runs on 10.3 Panther. Users of 10.3 Panther will however probably be better served by [Daniel Steffen]'s excellent [TclTkAquaBI]. As of October 2002, Tcl is very mature on Mac OS X, but the Aqua-Tk release is less mature than the releases on other platforms (this is still true in January 2004). This means it still contains some bugs which everyone is encouraged to report/fix. As problems are fixed, this page will be updated accordingly. Please note that the tools required to build TkAqua are free from Apple and that it is very easy to build. It is also pretty easy to get the most recent sources from cvs, so you can get all the latest fixes quickly and easily, yourself: See [Steps to build Tcl/Tk 8.4.0 on MacOS X]. <> Issues Patches outstanding: * IME: http://sourceforge.net/tracker/index.php?func=detail&aid=622582&group_id=12997&atid=312997 * CoreGraphics update: http://sourceforge.net/tracker/index.php?func=detail&aid=841244&group_id=12997&atid=312997 Approximate list of bugs: * SF tk bug list search for Aqua: http://sourceforge.net/search/?type=artifact&exact=0&q=Aqua&offset=0&group_id=12997&atid=112997 Issues fixed in cvs (but which may not be in a distributed binary release). * Changes to the contents of a label are not redrawn on 'update idletasks' (need a full 'update', I believe). For example Alphatk's status bar shows nothing during startup. This 'label .l ; pack .l ; for {set i 0} {$i < 50} {incr i} { .l configure -text [[string repeat $i 10]] ; update idletasks }' just doesn't do what you want at all! This is fixed in TOT, and I will add the fix to 8.4.6. We just needed to implement XSync. * File filters for tk_getOpenFile which specify a fileType and an extension will only match if the file type and extension match. But the default on Mac OS X is for files to have no file type, so these filters will always fail. The solution is that if both and extension & a file type are provided, we will pass files that match the extension, but have no fileType. * Using the scroll wheel on a Logitech optical mouse works for scrolling down but not for scrolling up. (the mouse works fine in other OS X applications). * Scrollbar "set" function gives unexpected results. If the slider is set to lenghts greater than 1/2 the total length of the scrollbar, it still displays as less than 1/2 the length of the scrollbar. * Unicode (non-Latin-1) characters font rendering (8.5). * Zoom support: to [[wm maxsize]] or screen size. Outstanding Bugs/Issues as of last change to this page (also see long list of bugs against tktoolkit project at sourceforge): * No support for -use option to wish, or indeed [Embedded Toplevels] across processes. * Conceptual problem with binds with the "Option" modifier. You can bind to , and you will get the event if that combination is pressed. But the text value is aring, U+00E5 "å", which you will also get in an entry widget, if you don't bind the key (on English and German Macs, other keyboards may assign different codes). You can not bind to or though. ''— [Lars H], 2008-07-21: This sounds like a strange interpretation; I can certainly bind to both and . The bindings to the former fires when I type an å, whereas bindings to the latter don't fire when I type an ü, but that's probably because I do have an Å key and no Ü key on my Swedish keyboard — aring is a '''key'''sym after all, not a charsym.'' * Key events only have keysyms for characters in the ASCII and Latin-1 range, so not e.g. for Hebrew or Greek. Event bindings for those "other" characters are also not possible for this reason. * Input method editors for Chinese etc. don't work. * Occasionally Wish gets confused and bindings don't seem to trigger. Switching to another application and back to Wish gets everything going again. * Builds on 10.2.x won't run on 10.1.x. * No images in menus. ([MAK] - More specifically, it will say "(Image)" for all items in a menu instead of the text if any items in the menu are given an image.) * You can select from a global menu even if there is a grab active. * Torn-off menus have some serious drawing problems: they initially show up as completely black (i.e. a large black rectangle), then as the mouse is moved over the entries, they are filled in, one at a time. * 'focus' and 'focus -force' either don't work or don't work properly. Certainly, for example, if the focus is currently in one toplevel, and you use 'focus -force' to move it to another toplevel, that doesn't raise the toplevel, and generally leaves Tk in a confused state, at times. ''Suggested solution: copy some of the implementation of TkpChangeFocus from tk/win/ to the Mac OS X implementation, which looks reasonably generic'' * tk_getChooseColor -title "Foo" ignores the title your provide. * Some encoding issues with file/dir paths in the save/open/directory dialogs * Checkbuttons with long text labels wrap in some circumstances, instead of being truncated. * Setting a button's -padx value to zero (it defaults to 12 (!)) causes a couple characters from the left and right of the button's -text attribute to be chopped off. * Scrollbars issue 'update idletasks' callbacks which have unintended consequences. Best to replace with a manual loop over Tcl_DoOneEvent (for windows events only), or redo the code so it looks more like the windows version which seems cleaner (but has to handle the same event loop issues). * 'tk_getSaveFile -defaultfile /Applications/Alphatk.app/Contents/foo' won't let you hit save (perhaps something to do with the file being inside a bundle?). However, 'tk_getSaveFile -defaultdir /Applications/Alphatk.app/Contents -defaultfile foo' is ok! * 'tk_getSaveFile -defaultfile ... -default dir ...' displays the whole filepath where it should just show the tail, and won't let you hit save. * 'tk_getSaveFile -defaultfile .foo' will not let you hit save. Any '.' file is illegal, it seems. * Menu -postcommand scripts that reconfigure or add/remove entries from menu bar sub-menus don't get reflected in the menu until the next time the menu is posted. Adding a call to "update idletasks" at the end of the script works around the problem. See [https://sourceforge.net/tracker/index.php?func=detail&aid=1068293&group_id=12997&atid=112997]. Popup menus (posted with tk_popup) don't exhibit the problem. Issues to be aware of, which may or may not be bugs: * The 'env' array is different for a graphical application versus a command-line one on Mac OS X. In particular your $env(PATH) is not the same. This means using 'exec' may fail to find the executable you were expecting. [[see note below]] * Small buttons are tricky, because they are very big. It may be necessary to extend TkAqua to include the small button controls provided by Carbon. As ever, the source code is available, so everyone is welcome to contribute. ---- There are some other issues I'm personally having trouble verbalizing (perhaps because I haven't yet investigated them much). For instance, [Bryan Oakley]'s combobox doesn't behave quite the same with respect to keyboard traversal. And there seems to be some issues with packing and/or gridding, but I'm not sure what that is. I see it when I run [tkdiff][[*]] on the mac -- some buttons don't seem to expand properly (ie: checkbuttons that look just great on windows and unix appear too short, which causes the text to wrap and the buttons to be illegible). Maybe this goes back to checkbuttons wanting to wrap rather than take as much horizontal space as possible, but I haven't yet been able to duplicate this easily. [Vince] adds: I think this is a bug in which the 'winfo reqwidth' of a checkbutton returns the reqwidth of the text, but doesn't add on the width of the checkbox bit. Does that make sense? Tkdiff also shows another anomolie I haven't yet tracked down. In its default mode, buttons in the toolbar appear with the text behind the image. The code was originally constructed to assume if you turn images on, the text gets turned off. It could be a bug in tkdiff, but the bottom line is that the mac version is different than on unix and windows. [Vince] It shouldn't show both unless you have '-compound', and shouldn't put them on top of each other unless there is '-compound center', so I imagine this is a bug. [[*]] the version of tkdiff available from accurev has a bug which prevents it from being run on 8.4, but it's an easy fix. There are a couple places that do "-pad 4" when it should be "-padx 4". Old problems which have been fixed and appear in a binary release (since July 9th): * [[file copy]] doesn't copy the resource fork and the Mac OS extra file attributes. In the same vein [[file attributes]] and other functions don't know about these. There's a TIP available and a patch to implement this functionality (in Tcl 8.5a0) * Stdin seems, for lack of a better word, funky. On windows and unix we have an app that takes input from stdin and displays it in a dialog (useful for piping output from a spawned process). Typical usage (paraphrased): "exec somethingInteresting | wish dialog.tcl -". works great on windows and unix. Oddly, if I do "wish dialog.tcl -" it works -- I can type data in, type ^D, and what I typed in appears. But if I pipe to wish (which is an alias to wish.app), the read returns an empty string. My code does the moral equivalent of "if {$filename == "-"} {set data [[read stdin]]}". * Current builds on 10.2.x crash if you click in scrollbars anywhere except on the blue bar. * sometimes 'cmd' accelerator is shown in menus when it shouldn't be. * fix to some problems with dead-keys now checked in. * Menu accelerators don't appear in the menus * lots of encoding problems with menus, labels, buttons, checkbuttons etc. * the virtual events <> <> etc are bound to 'ctrl-z/x/c/v' instead of 'Command-z/x/c/v' which is the Mac OS X default. * Menu entries with key-bindings are activated even if there are grabs or global grabs active on other widgets * tk::PlaceWindow needs to avoid placing windows under the menubar * wm attributes broken * 'Leave' events seem to be generated even when just circulating inside a widget, when the widget has a balloon-help window associated with it (i.e. there is a floating window around, but nowhere near the mouse). I've done some debugging of this, but haven't yet tracked down whether this is because the wrong window is directly found or because the floater confuses the x,y coords of the event so it then picks the wrong window. Either way the result is that Tk believes the mouse is moving back and forth from '.' to '.win' when it moves (where .win is the thing you are circulating over). * when floating windows are present (tk::unsupported::MacWindowStyle style .foo floating sideTitlebar), mouse events in other windows are screwed up. In particular they are offset in x/y coordinates from where they should be. (So, you click in a text widget, and the cursor moves somewhere else). * events for single modifier keypresses (on their own), e.g. "Control" are not available (the appropriate conversion from Carbon->Tk event doesn't happen). 28sep02 [jcw] - Wish can be opened with the "open" command from the command line, but the only way to pass it cmdline-args seems to be to type: /Contents/MacOS/Wish\ Shell arg1 arg2 ... Also note that a script cannot yet be dropped on Wish to launch it. 8feb03 [UKo] - but now the 8.4.1 wish can be choosen as starting application for files with tcl-extension 03oct02 - [jcw] - Another tip from [Jim Ingham]: if a file is called "blah.command" (say a shell script), then double-clicking it brings up a Terminal window and runs the command in it (at least on 10.2). This does not seem to work when it's a symlink, so better make a copy (or a hard link, I s'pose). 3mar03 - [Daniel Steffen] - My '''Launcher''' [http://www.maths.mq.edu.au/~steffen/tcltk/Launcher/] utility helps with this (included with [TclTkAquaBI] or available separately). 18dec02 - [Benny Riefenstahl] - The 'problem' with the env array is generic to Mac OS X/Aqua. On all Unixes the environment variables are set in shell scripts like ~/.profile, ~/.cshrc or similar. On Aqua the Finder is the login shell, it inherits its environment from the loginwindow application and that can be configured in ~/.MacOSX/environment.plist, see Apple Technote at [http://developer.apple.com/qa/qa2001/qa1067.html]. Of course, if it is for Tcl only, you can just put additions to the environment variables into ~/.[tclshrc]. <> ----- A recent question on comp.lang.tcl was asking how one sets up Tcl/Tk Aqua on Mac OS X so that a Tcl/Tk script could be double clicked and launch appropriately. 08feb03 [UKo] The current 8.4.1 Wish is able to respond to the "open" Apple Event and can thus be choosen as application for opening files with the tcl-extension. For older versions (and the last tclkit that runs on non-Jaguar) one can make a applescript like this to start a specific tcl-script or startkit -- here my applescript for starting the local wikit copy: do shell script "tclkit ~/bin/wikit.kit ~/bin/wikit.tkd" (be sure to use the POSIX pathnames!) And here a script that starts a tclkit for every file that is dropped on the script: on open names repeat with kit in names set command to "tclkit " & (POSIX path of kit as string) & "" -- ignoring application responses do shell script command -- end ignoring end repeat return end open save this from the applescript editor as program and the you can choose it as open application for any starkit or just drag'n'drop the kit onto the script -- voila. '''TODO''' unfortunately the applescript and the tclkit will both be open -- I don't know how tho make the applescript finish and the tclkit keep on running. (as far as I understand this should be done with the "ignoring" statement -- but it doesn't work for me) 3mar03 - [Daniel Steffen] - It's probably easier to use my '''Launcher''' [http://www.maths.mq.edu.au/~steffen/tcltk/Launcher/] utility for this (included with [TclTkAquaBI] or available separately). ----- Apparently it's important for those working with MacOS X to know about [fink], which provides the user the ability to keep installed packages up to date. No - it's not important to know about fink - the standard MacOSX developer tools are quite sufficient. However, if you want to have a "Debian Linux-like" environment under MacOSX then fink will be of interest. I had fink installed but removed it ... it's fine in what it does but I prefer to work with the Apple tools as far as I can - [stevel] Feb 9, 2003 There is also Darwinports [http://www.darwinports.org], which is an alternative package manager. Note that this is actually Tcl-based. ;-) [BR] ---- X11 is included in the Mac OS X installation disks since 10.3 as an optional package. [BR] ---- 2003Sep18: On the [Mactcl] mailing list, [Jim Ingham] and Kevan Hashemi were discussing what was needed when writing a dynamically loadable extension for Mac OS X. Kevan discovered that: gcc -c ${INCL} lwdaq.c -o lwdaq.o \ -I/library/frameworks/tk.framework/headers \ -I/library/frameworks/tcl.framework/headers gcc -dynamiclib -o Lwdaq.dylib -framework Tcl -framework Tk lwdaq.o for his C code resulted in code that is loadable. ---- 2003 Oct 28: On the Mactcl mailing list, Kevan Hashemi and [Daniel Steffen] answer the question ''What do I need to do to get a development environment on a Mac OS X machine?'' 1. Install the December 2002 Mac OS X Developer Tools software package 1. Go to https://connect.apple.com/ and open a free membership account with the Apple Developer Connection. 1. Log on, click on download software, then click on developer tools. 1. You need to get the gcc updater (currently it is the august gcc 3.3 updater). 1. Start a terminal command line program and you should now find gcc. [Jason Tang] Macs with a Panther install CD/DVD instead must use that disc to run the supplementary applications installer. From there install development tools. Now go to /Applications/Utilities/Installer and run the development tools installer. [DAS] goes on to say: for TEA based extensions, the following configure invocation should do the trick: ./configure \ --prefix=/usr/local --libdir=/Library/Tcl \ --with-tcl=/Library/Frameworks/Tcl.framework \ --with-tclinclude=/Library/Frameworks/Tcl.framework/Headers \ --with-tk=/Library/Frameworks/Tk.framework \ --with-tkinclude=/Library/Frameworks/Tk.framework/Headers \ --enable-threads You should probably link with stub libraries like on other unix platforms: gcc -dynamiclib -o yourdylib.dylib yourcommands.o \ -L /Library/Frameworks/Tcl.framework/ -ltclstub8.4 \ -L /Library/Frameworks/Tk.framework -ltkstub8.4 You can build tcl & tk with X11 yourself in the standard unix manner and install into e.g. /usr/local and not bother with the framework based TkAqua. You'll need X11 & X11SDK from Apple: http://www.apple.com/macosx/features/x11/download/ ---- Others working with Mac OS X include [William Duquette], [Jeffrey Hobbs], [Cameron Laird], [Steve Landers], [Bryan Oakley], and [Jean-Claude Wippler]. ---- [LES] on Feb 13, 2004: I was wondering how different [MacOS X] and [Darwin] are. I know Tcl/Tk run on both, but is it the same Tcl/Tk or are different ports required for each one? ---- [MKS] on Monday, 31 May 2004: Thanks to the help of Benjamin Riefenstahl, I was able to put together a means of having Aqua and X11 installations of Tcl/Tk coexist on the same machine, sharing packages where possible. I compiled the 'unix' codebase and installed it in /usr/local with: cd $tclsource/unix ./configure --prefix=/usr/loca/ --enable-threads && make && make install cd $tksource/unix !-2 Then installed the "Batteries Included" binary release of the Aqua version. To make the two versions share packages, I added the following to my ~/.tclshrc: ====== proc auto_path_handler {} { set ::auto_path_x11 [list /usr/local/lib/tcl8.4 /usr/local/lib] set ::tcl_pkgPath_x11 [list /usr/local/lib] set ::auto_path_aqua [list \ /Library/Frameworks/Tcl.framework/Versions/8.4/Resources/Scripts \ /Library/Frameworks/Tcl.framework/Versions/8.4/Resources \ /usr/lib ~/Library/Tcl /Library/Tcl /Network/Library/Tcl \ /System/Library/Tcl ~/Library/Frameworks /Library/Frameworks \ /Network/Library/Frameworks /System/Library/Frameworks] set ::tcl_pkgPath_aqua [list \ /Library/Frameworks/Tcl.framework/Versions/8.4/Resources/Scripts \ ~/Library/Tcl /Library/Tcl /Network/Library/Tcl /System/Library/Tcl \ ~/Library/Frameworks /Library/Frameworks /Network/Library/Frameworks \ /System/Library/Frameworks] # if the path to the executable contains /local, then it is the X11 # installation, otherwise it is the Aqua installation: if {(([regexp {/local} $::argv0]) || ([regexp {/local} [info nameofexecutable]]))} { set ::auto_path [concat $::auto_path_x11 $::auto_path_aqua] set ::tcl_pkgPath [concat $::tcl_pkgPath_x11 $::tcl_pkgPath_aqua] } else { set ::auto_path [concat $::auto_path_aqua $::auto_path_x11] set ::tcl_pkgPath [concat $::tcl_pkgPath_aqua $::tcl_pkgPath_x11] } return "" } auto_path_handler ====== These directories are specific to my installation. The best way to determine what yours should be is to start up both tclsh executables and copy out the values given for auto_path and tcl_pkgPath. This has the effect of allowing package inclusion to search the appropriate location first for either given release, based on which binary is run. Note X11 and Aqua CANNOT share Graphical packages (though the tclsh that ships with Aqua can load the X11 Tk, and thereafter use X11). In the event that an Aqua binary tries to require a package that is only present in the X11 tree (or vice versa) bad things may happen. ---- Tk-based applications can look quite good under Aqua. [Kevin Walzer] gives examples [http://sourceforge.net/mailarchive/forum.php?thread_id=5140773&forum_id=3853]. [More MacOS X techniques] [New Tcl/TkAqua FAQ] ---- [RLH] 2006-10-08: Where does [ActiveTcl] puts it libraries and stuff? Where would I put my own package to have it picked up by tclsh? ---- In May 2008, [Kevin Walzer] lists [http://article.gmane.org/gmane.comp.lang.tcl.mac/5990] the principal actors involved in Tcl/Tk for Mac OS. <> Operating System | Mac