On macOS
ztk has a native backend for macOS 13 and later. It uses AppKit for the windows, the input, and the menus, and Metal for the drawing, with no layer between ztk and macOS.
Build and run
Install Zig 0.16.0 and the Xcode command line tools (xcode-select --install).
git clone https://github.com/beetlebugorg/ztk
cd ztk
zig build -Doptimize=ReleaseFast # makes zig-out/bin/ztk
zig-out/bin/ztk examples/demo.tcl # opens a window
ztk --headless works as on the other systems, with no window.
Make an app
ztk bundle makes a macOS app, a folder Name.app, from a main script and its files:
ztk bundle -o Notes.app --icon notes.png --id org.example.notes notes.tcl lib/ images/
open Notes.app
The app has a copy of the ztk program, the scripts and the files in Contents/Resources/app, an icon set made from the PNG, and an Info.plist. Each file keeps its path relative to the main script, as for an app in one file. The app runs its main script with the folder app as the root of the file commands. Each word of the command line of the app is an argument of the script, so a flag cannot add a capability. ZTK_HEADLESS=1 in the environment runs the app headless, for example ZTK_HEADLESS=1 Notes.app/Contents/MacOS/Notes.
| Option | Meaning |
|---|---|
-o Name.app |
The app to write. The name of the app comes from it. |
--name NAME |
Another name for the app. |
--id ID |
The bundle identifier, such as org.example.notes. The default is org.ztk. and the name. |
--version V |
The version. The default is 1.0. |
--icon FILE.png |
The icon: a square 8-bit RGBA PNG, 1,024 pixels or less. |
--allow CAPS |
The capabilities of the app, as for ztk --allow. The default is file,channels. |
--menu-bar-only |
No Dock icon and no menu bar (LSUIElement), for an app that lives in a tray icon. |
--target T |
aarch64-macos or x86_64-macos: the macOS ztk program to copy is lib/ztk/runtime/T/ztk next to the folder of ztk, or --runner. |
--runner FILE |
The macOS ztk program to copy. The default is the program that runs the command. |
--no-sign |
Leave the app unsigned. The default is an ad hoc signature with the entitlement com.apple.security.cs.allow-jit. |
A bundle can come from Linux or Windows too: give --target aarch64-macos or a macOS ztk with --runner, for example ztk bundle -o Notes.app --target aarch64-macos notes.tcl. Windows has no mode bits for files, so an app from Windows needs chmod +x Name.app/Contents/MacOS/Name on the Mac. ztk bundle signs the app with an ad hoc signature: on macOS with codesign, and on Linux and Windows with its own signer, which writes Contents/_CodeSignature/CodeResources and the signature of the program. Run the app on the Mac that made it, or sign it as below before you give it to others.
Sign and notarize an app
An app for other people needs a Developer ID signature and a notarization from Apple, or macOS refuses to open it. Each step needs an Apple Developer account.
-
Sign the app with your Developer ID and the hardened runtime:
codesign --force --options runtime --timestamp \ --sign "Developer ID Application: Your Name (TEAMID)" Notes.appA ztk program that runs scripts with the JIT of ztcl needs the entitlement
com.apple.security.cs.allow-jitas well: give a plist with it to--entitlements. -
Send a zip of the app to Apple, wait for the answer, and staple the ticket to the app:
ditto -c -k --keepParent Notes.app Notes.zip xcrun notarytool submit Notes.zip --keychain-profile notary --wait xcrun stapler staple Notes.appxcrun notarytool store-credentials notarysaves the profile one time.
Window state
wm attributes .w -fullscreen 1 takes the window to the full screen of macOS (a space of its own, with the animation of the system), and -fullscreen 0 brings it back. -topmost 1 keeps it above the windows of other apps, at the level of floating panels. ztk::animate reads Reduce motion of the Accessibility settings at the start and again when it changes, and shows each end state at once while it is on.
Drops from other apps
A window that takes drops (ztk::dnd) gets the files of Finder and the text of other apps: the view registers for file URLs and plain text, as the window accepts them, and each phase of the drag (enter, over, leave, drop) is a drop event. The files are host paths. A drag that has no kind that the window takes shows no drop, and the app finds the widget at the point. A drag out of a window is ztk::dnd drag, below.
Drags to other apps
ztk::dnd drag drags files or text out of a window to other apps, from a binding of <B1-Motion>: an NSDraggingSession of the window, with the icon of each file, and it gives copy, move (with -move 1), or none when the drag ends.
Direct APIs of macOS
The commands of ztk::mac::* exist on each platform and give the error ZTK MAC UNAVAILABLE away from macOS. ztk::has mac gives 1 where they work.
menu .dock -tearoff 0
.dock add command -label "New Window" -command newWindow
ztk::mac::dockmenu .dock ;# the menu of the Dock icon; no menu name removes it
ztk::mac::tabbing . -mode preferred -group documents
-mode is automatic (the setting of the system), preferred (new windows open as tabs), or disallowed (no tab bar). Windows of one -group join one tab bar. A file dialog with -parent shows as a sheet of its window, and so does tk_messageBox (an NSAlert with the buttons of Tk, the default button on the right for Return). tk_chooseColor opens the color panel of macOS and gives its color when the panel closes; the panel has no Cancel, so the answer is the color at the close. The application menu has the Services menu.
The design and the plan are in docs/dev/macos.md.