Minimal Tcl/Tk Mac Application Packages
Here is one way to create a self-contained double-clickable Tcl/Tk application for Mac OS X.
Save this text as
package require Tk pack [label .l -text "Hello, World!" -padx 30 -pady 30]
For clarity, save this and other example files to the Desktop.
Update: On Mac OS X 10.5 (“Leopard”), at least with current X11 patches, you can use non-Aqua Tclkits as the basis for Mac application packages. X11 will open automatically. Since Tk Aqua doesn’t play well with Leopard, this may prove to be a useful (if ugly) interim solution.
Updatiest: You can now build your own tclkits with ease using the Kitgen Build System.
sdx.kit from the SDX web page. SDX is a utility that can, among other things, create executable Starpacks by joining Tclkit interpreters with your Tcl code. (Safari may warn that the file is executable and append
.sh to its name; just remove the
.sh after downloading.)
Open Terminal and change to the directory containing these files:
Make an executable copy of the Tclkit.
cp tclkit-darwin-univ-aqua tclkit chmod +x tclkit
The duplicate is needed because Tclkit is used both to execute SDX and as input to SDX. It cannot otherwise operate on itself.
Create the Starpack by “quick wrapping” the sample code:
./tclkit sdx.kit qwrap hello.tcl -runtime tclkit-darwin-univ-aqua
This yields the executable file
hello, which you can run from the command line:
Different Tclkits can be used to create executables for different platforms. Omitting the
-runtime argument creates a platform-independent Starkit which can be executed by an external Tclkit. Instead of
qwrap, more complex projects can use the
wrap command to package their entire directory structure as a virtual filesystem.
Every application needs a good icon. This is not a good icon, but it will suffice as an example:
Create a folder called
Hello World.app. Because the
app extension designates an application, the Finder will treat the folder as an application package. Control-click the embryonic application and select “Show Package Contents”:
Create a folder called
Contents inside the package, and two folders titled
Resources and the
hello executable into
Every application contains a file that lists certain application properties. Because some properties identify the very components that comprise the application, the application won’t work without this vital file.
Here is an example
Info.plist. Place this file in the package’s
Note that the
CFBundleExecutable property identifies the executable (found in
MacOS) and that
CFBundleIconFile identifies the application icon (found in
CFBundleSignature properties should be unique to your application. The
CFBundleVersion properties specify your application’s version.
Consult Apple’s Property List Key Reference for more details about these and other possible application properties. As XML files, property lists can be edited with text editors or Apple’s dedicated Property List Editor (included with the developer tools).
The application package should now be organized like this:
Hello World.app /Contents Info.plist /MacOS hello /Resources hello.icns
It may be necessary to temporarily rename the application in order for the Finder to recognize the new package information.
Hello World.app will adopt the
hello.icns icon. Give it a double-click:
The default menu bar items and window title are provided by Tk. The internal
main.tcl filename is introduced by
So, that’s a tidy way to package a Tcl/Tk program for Mac OS X deployment. The application package is really just a few folders, an icon, and a property list wrapped around a Starpack. If you’re already using Starkits, you’re only a few steps away from delivering a relatively well-integrated Macintosh version of your application.
The technique described here is largely inspired by Kevin Walzer’s How to Build Tcl/Tk Application Bundles the Mac Way tutorial. The companion article on Tk Aquafication offers more guidance on integration with Macintosh interface conventions.
Info.plist is based on the property list included in the Tcl/Tk Aqua 8.4.16 standalone Wish Shell, which I cannot find listed on any relevant web sites. As with other recent releases, it seems to be available only by direct download from mailing list announcements.