Develop on macOS
This page is the loop of a developer on a Mac: run a script, find a bug, test the window, and make an app for other people. Each step uses the ztk program of Install.
Run a script
ztk app.tcl
The program runs until the last window closes or the script calls exit. After you change the script, close the window and run the command again.
| Output | Where it goes |
|---|---|
puts |
The terminal. |
An error in a binding or a -command |
The terminal. The window stays open. |
| An error in the main script | The terminal. The program ends with the status 1. |
The words after the script name go to $argv. The flags before it change the program:
| Flag | What it does |
|---|---|
--dark |
Uses the dark scheme. With no flag, the window follows the appearance of macOS. |
--allow a,b |
Turns on more capabilities of the script, such as exec or socket. The file commands, the file channels, and the clock are on with no flag. |
--root DIR |
Keeps the file commands in one folder. |
--tcl 8.6 |
Runs the script as Tcl and Tk 8.6. The default is 9.1. |
The ztk program has each flag, and Quick start has a first script with a style sheet.
Find a bug
ztk::debug tells you why a widget looks or acts as it does. It gives the source of each option, the geometry chain of a size, and what ran for a click.
ztk::debug sources on
ttk::button .ok -text Save
pack .ok
.ok configure -state disabled
puts [ztk::debug why .ok -state]
The output names the line that set the option. Debugging has each tool, and ztk --mcp app.tcl gives them to an agent.
See the window with no screen
--headless draws the window with the CPU renderer and opens no window. With --screenshot, it writes the last frame to a PNG file:
ztk --headless --scale 2 --exit-after-frames 2 --screenshot app.png app.tcl
A headless picture has the look of ztk on Linux. The headless program has no AppKit theme and no Core Text. Use it for tests and for a check of the layout.
Test the window
A test drives the window with ztk::inject and reads it with ztk::tree. It runs with --headless, so the same test runs on a Mac, in CI on Linux, and on Windows.
ztk --headless test.tcl
For agents has a test that clicks a button and checks the count.
Make an app
ztk bundle writes a Mac app, a folder Name.app, from the main script and its files:
ztk bundle -o Notes.app --icon notes.png --id org.example.notes \
--version 1.2 notes.tcl lib/ images/
open Notes.app
The app folder has these parts:
| Part | What it is |
|---|---|
Contents/MacOS/Notes |
A copy of the ztk program. |
Contents/Resources/app |
The scripts and the files, each at its path relative to the main script. This folder is the root of the file commands. |
Contents/Resources/AppIcon.icns |
The icon set, made from the PNG. |
Contents/Resources/ztk.conf |
The name of the main script and the capabilities. |
Contents/Info.plist |
The name, the identifier, and the version. |
The words of the command line of the app go to $argv, so a flag cannot add a capability. The options of ztk bundle for a Mac app:
| Option | What it does |
|---|---|
-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. 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. The default is file,channels,clock. |
--menu-bar-only |
No Dock icon and no menu bar, for an app that lives in a menu bar icon (macOS features). |
--target T |
aarch64-macos or x86_64-macos, for an app of the other kind of Mac. |
--no-sign |
Leaves the app unsigned. |
ZTK_HEADLESS=1 runs the app with no window, for a test of the app itself:
ZTK_HEADLESS=1 Notes.app/Contents/MacOS/Notes
A Linux or a Windows computer can also make a Mac app. Give --target aarch64-macos, and the Mac program of that target with --runner or in lib/ztk/runtime/aarch64-macos/ next to ztk. An app from Windows needs chmod +x Name.app/Contents/MacOS/Name on the Mac.
Sign and notarize the app
ztk bundle gives the app an ad hoc signature, so it runs on the Mac that made it. Another Mac opens only an app with a Developer ID signature and a notarization from Apple. Both steps need an Apple Developer account.
-
Sign the app with your Developer ID and the hardened runtime. Give the entitlement
com.apple.security.cs.allow-jitin a plist, because the Tcl interpreter of ztk has a JIT compiler:codesign --force --options runtime --timestamp \ --entitlements jit.plist \ --sign "Developer ID Application: Your Name (TEAMID)" Notes.app -
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.
The file jit.plist has one key:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>com.apple.security.cs.allow-jit</key><true/>
</dict></plist>
Give the app to other people as the stapled Notes.app in a zip or a disk image. They drag it to the Applications folder.
The next page, Widgets, shows how the widgets look and act on macOS.