Adding a Toolbar to Your App
Toolbars give your app a native, professional feel — the same row of icon buttons you see in Finder, Mail, and most other desktop apps. This guide walks you through adding one to an existing HyperXTalk stack, step by step.
- A native toolbar attached to your stack window
- Toolbar buttons with SF Symbols icons and labels
- Click handlers wired up in your stack script
- The ability to show and hide the toolbar on demand
Step 1 — Create the Toolbar
Open the stack you want to add a toolbar to and go to the stack script. The first thing you need to do is create the toolbar itself. The best place to do this is in an openStack handler so it's ready as soon as the stack opens:
The string "mainBar" is the identifier you'll use to refer to this toolbar in every subsequent command. Choose something descriptive — if your app has different toolbars for different modes, names like "editBar" or "formatBar" make things clearer.
Step 2 — Add Toolbar Items
Each button in the toolbar is called an item. You define items by setting their label and icon, then tell the toolbar which items to show and in what order.
Set labels and icons
Set the item order
Setting labels and icons registers the items but doesn't add them to the visible toolbar yet. You control which items appear — and in what order — by setting itemNames to a return-separated list:
You can reorder items at any time by setting itemNames again. Items not in the list are hidden but not deleted — useful if you want to swap toolbars between modes.
Step 3 — Choose Your Icons
Icons are specified using SF Symbols names — Apple's built-in icon library with over 6,000 symbols. Download the free SF Symbols app to search and preview them. You can also use an image imported into your stack by passing its filename instead of a symbol name:
Step 4 — Show the Toolbar
Back in your openStack handler, after all the item setup, make the toolbar visible:
You can toggle visibility at any time — for example from a View menu item:
Step 5 — Handle Button Clicks
When the user clicks a toolbar button, HyperXTalk sends a toolbarItemClicked message with the item's identifier as a parameter. Add this handler to your stack script or card script — not an object script:
The switch statement is the cleanest way to handle multiple buttons — it checks pItemName against each case and runs the matching block. Add as many cases as you have toolbar items.
Putting It All Together
Here's the complete stack script with everything in place: