tk::mac(n)
β¨ tk::mac β the macOS Tk hookup manual β¨
okay so bestie, this is the <purple>tk::mac</purple> page from the Tk built-in commands manual (8.6, dated 8.6). it's literally your whole guide to accessing Mac-specific functionality on macOS from Tk. iykyk. π
πΈ SYNOPSIS πΈ
::tk::mac::DoScriptFile
::tk::mac::DoScriptText
::tk::mac::ShowPreferences
::tk::mac::OpenApplication
::tk::mac::ReopenApplication
::tk::mac::OpenDocument file...
::tk::mac::PrintDocument file...
::tk::mac::Quit
::tk::mac::OnHide
::tk::mac::OnShow
::tk::mac::ShowHelp
::tk::mac::PerformService
::tk::mac::LaunchURL URL...
::tk::mac::GetAppPath
::tk::mac::standardAboutPanel
::tk::mac::useCompatibilityMetrics boolean
::tk::mac::CGAntialiasLimit limit
::tk::mac::antialiasedtext number
::tk::mac::useThemedToplevel boolean
::tk::mac::iconBitmap name width height -kind value
π EVENT HANDLER CALLBACKS π
okay so the Aqua/macOS app environment defines a bunch of extra events that applications should respond to. Tk maps these events to calls to commands in the ::tk::mac namespace; unless otherwise noted, if the command is absent, no action will be taken. no cap. π«Ά
::tk::mac::DoScriptFileβ the default Apple Event handler forAEDoScriptHandler. this command executes a Tcl file when an AppleScript sends a βdo scriptβ command to Wish with a file path as a parameter. iconic. β¨::tk::mac::DoScriptTextβ the default Apple Event handler forAEDoScriptHandler. this command executes Tcl code when an AppleScript sends a βdo scriptβ command to Wish with Tcl code or a Tcl procedure as a parameter. slay. π::tk::mac::ShowPreferencesβ the default Apple Event handler forkAEShowPreferences, βprefβ. the application menu βPreferencesβ menu item is only enabled when this proc is defined. typically this command is used to wrap a specific own preferences command, which pops up a preferences window. something like:
proc ::tk::mac::ShowPreferences {} {
setPref
}
obsessed. π
::tk::mac::OpenApplicationβ if a proc of this name is defined, this proc fill fire when your application is initially opened. it is the default Apple Event handler forkAEOpenApplication, βoappβ. main character energy. π::tk::mac::ReopenApplicationβ if a proc of this name is defined it is the default Apple Event handler forkAEReopenApplication, βrappβ, the Apple Event sent when your application is opened when it is already running (e.g. by clicking its icon in the Dock). here is a sample that raises a minimized window when the Dock icon is clicked:
proc ::tk::mac::ReopenApplication {} {
if {[wm state .] eq "withdrawn"} {
wm state . normal
} else {
wm deiconify .
}
raise .
}
lowkey so cute. π¦
::tk::mac::OpenDocument file...β if a proc of this name is defined it is the default Apple Event handler forkAEOpenDocuments, βodocβ, the Apple Event sent when your application is asked to open one or more documents (e.g., by drag & drop onto the app or by opening a document of a type associated to the app). the proc should take as arguments paths to the files to be opened, like so:
proc ::tk::mac::OpenDocument {args} {
foreach f $args {my_open_document $f}
}
the way that just works. π
::tk::mac::PrintDocument file...β if a proc of this name is defined it is the default Apple Event handler forkAEPrintDocuments, βpdocβ, the Apple Event sent when your application is asked to print a document. it takes a single absolute file path as an argument. periodt. π¨οΈ::tk::mac::Quitβ if a proc of this name is defined it is the default Apple Event handler forkAEQuitApplication, βquitβ, the Apple Event sent when your application is asked to be quit, e.g. via the quit menu item in the application menu, the quit menu item in the Dock menu, or during a logout/restart/shutdown etc. if this is not defined,exitis called instead. no cap, that's the default. π::tk::mac::OnHideβ if defined, this is called when your application receives akEventAppHiddenevent, e.g. via the hide menu item in the application or Dock menus. hide & seek vibes. π::tk::mac::OnShowβ if defined, this is called when your application receives akEventAppShownevent, e.g. via the show all menu item in the application menu, or by clicking the Dock icon of a hidden application. showtime, bestie. π::tk::mac::ShowHelpβ customizes behavior of Apple Help menu; if this procedure is not defined, the platform-specific standard Help menu item βYourApp Helpβ performs the default Cocoa action of showing the Help Book configured in the application'sInfo.plist(or displaying an alert if no Help Book is set). help me help you. π::tk::mac::PerformServiceβ executes a Tcl procedure called from the macOS βServicesβ menu in the Application menu item. the βServicesβ menu item allows for inter-application communication; data from one application, such as selected text, can be sent to another application for processing, for example to Safari as a search item for Google, or to TextEdit to be appended to a file. an example of the proc is below, and should be rewritten in an application script for customization:
proc ::tk::mac::PerformService {} {
set data [clipboard get]
$w insert end $data
}
note that the mechanism for retrieving the data is from the clipboard; there is no other supported way to obtain the data. if the Services process is not desired, the NSServices keys can be deleted from the application's Info.plist file. the underlying code supporting this command also allows the text, entry and ttk::entry widgets to access services from other applications via the Services menu. the NSPortName key in Wish's Info.plist file is currently set as βWishβ ; if a developer changes the name of the Wish executable to something else, this key should be modified with the same name. it's giving β¨ clipboard energy β¨. π
::tk::mac::LaunchURL URL...β if defined, launches a URL within Tk. this would be used if a Tk application wants to handle a URL itself, such as displaying data from an RSS feed, rather than launching a default application to handle the URL, although it can defined as such. Wish includes a stub URL scheme of βfoo://β in theCFBundleURLSchemeskey of itsInfo.plistfile; this should be customized for the specific URL scheme the developer wants to support. π::tk::mac::GetAppPathβ returns the current applications's file path. where u at? π
π ADDITIONAL DIALOGS π
Aqua/macOS defines additional dialogs that applications should support. bestie, these are the extra pop-ups. π¬
::tk::mac::standardAboutPanelβ brings the standard Cocoa about panel to the front with information filled in from the application bundle files. the panel displays the application icon and the values associated to theinfo.plistkeys namedCFBundleName,CFBundleShortVersionString,NSAboutPanelOptionVersionandNSHumanReadableCopyright. if a file namedCredits.htmlorCredits.rtfexists in the bundle's Resources directory then its contents will be displayed in a scrolling text box at the bottom of the dialog. see the documentation for-[NSApplication orderFrontStandardAboutPanelWithOptions:]for more details. a hook is also provided for a custom About dialog. if a Tcl proc namedtkAboutDialogis defined in the main interpreter then that procedure will be called instead of opening thestandardAboutPanel. so you can make it all custom and cute. π¨
π¦ SYSTEM CONFIGURATION π¦
there are a number of additional global configuration options that control the details of how Tk renders by default. these are the vibe checks for your whole app's look. β¨
::tk::mac::useCompatibilityMetrics booleanβ preserves compatibility with older Tk/Aqua metrics; set tofalsefor more native spacing. lowkey important. π::tk::mac::CGAntialiasLimit limitβ sets the antialiasing limit; lines thinner thatlimitpixels will not be antialiased. integer, set to0by default, making all lines be antialiased. so smooth. π§::tk::mac::antialiasedtext numberβ sets anti-aliased text. controls text antialiasing, possible values fornumberare-1(default, use system default for text AA),0(no text AA),1(use text AA). pick your fighter. π€::tk::mac::useThemedToplevel booleanβ sets toplevel windows to draw with the modern grayish/ pinstripe Mac background. equivalent to configuring the toplevel withβ-background systemWindowHeaderBackgroundβ, or to using attk::frame. fancy. πͺ
π SUPPORT COMMANDS π
::tk::mac::iconBitmap name width height -kind valueβ renders native icons and bitmaps in Tk applications (including any image file readable byNSImage). a native bitmapnameis interpreted as follows (in order):- predefined builtin 32x32 icon name (
stop,caution,document, etc.) name, as defined bytk::mac::iconBitmapNSImagenamed imagenameNSImageurl string- 4-char
OSTypeofIconServicesicon
- predefined builtin 32x32 icon name (
the width and height arguments to tk::mac::iconBitmap define the dimensions of the image to create, and -kind must be one of:
-fileβ icon of file at given path-fileTypeβ icon of given file type-osTypeβ icon of given 4-charOSTypefile type-systemTypeβ icon for givenIconServices4-charOSType-namedImageβ namedNSImagefor given name-imageFileβ image at given path
icon queen behavior. ππ
π SEE ALSO π
β KEYWORDS β
about dialog, antialiasing, Apple event, icon, NSImage
okay that's the whole thing bestie! go forth and make your Mac app iconic. π«Άπ
this has been your Tk 8.6 tk::mac manual moment, brought to you by the Tk built-in commands collection. go slay. β¨πΈ
π¦ where this page comes from
- alpine 3.22: tk-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tk-doc 8.6.17-r0 Β· TCL
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk-doc 8.6.17-r1 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- arch rolling: tk 8.6.16-1 Β· TCL
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- Copyright (c) 2011 Kevin Walzer
- Copyright (c) 2011 Donal K. Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms