swiftpm-app-bundle
Skill0 starsChanged 3 months agoMITView on GitHub
Package a Swift Package Manager (SwiftPM) executable target — an AppKit or SwiftUI app built without an Xcode project — into a distributable macOS .app bundle and an unsigned .dmg. Use when the user wants to package .app, build a DMG, turn a SwiftPM executable to app bundle, prepare a menu bar app distribution, ship a Swift command-line/GUI target as a double-clickable Mac app, or asks about Info.plist / .icns / LSUIElement / codesign / notarization for a package-based (no .xcodeproj) macOS app. Trigger with "/swiftpm-app-bundle".
In this repository4 other files it gives its agents.
- macos-app-iconSkill
- oss-readiness-auditSkill
- swift-ci-portabilitySkill
- swift-release-flowSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 2 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 37
Does not sign or notarize anything (see references/signing-notarization.md for that — it requires a paid Apple Developer account).
- Distinctive: line 39
Does not create an Xcode project.
- Very specific: line 75
Every value that ends up in a path or in Info.plist is validated before the script touches the filesystem, and the run stops with a clear …
- Very specific: line 115
If there are multiple executable products, ask the user which one they mean, or pass --app-name / --product explicitly (--product matters …
- Distinctive: line 124
Should not show a Dock icon or appear in the Cmd-Tab app switcher.
- Very specific: line 126
Leave it unset (LSUIElement=false, the default) for a normal windowed app that should appear in the Dock and app switcher as usual.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftPM App Bundle
Overview
Turns a SwiftPM .executableTarget into a real macOS .app bundle plus an
unsigned .dmg, with no Xcode project involved. This is the common path for
small AppKit/SwiftUI utilities (menu bar apps, single-window tools) that are
built with swift build and never had an .xcodeproj to begin with.
Prerequisites
- macOS 12+ with Xcode Command Line Tools (
swift,codesign,xcrun). hdiutil(bundled with macOS) for DMG creation.- A
Package.swiftwith at least one.executableproduct.
When to use this skill
- The repo has a
Package.swiftwith an.executableproduct but no.appbundle, no.xcodeproj/.xcworkspace, and the user wants something they (or testers) can double-click, or a.dmgto hand out. - The user mentions: "package .app", "make a DMG", "SwiftPM executable to app bundle", "menu bar app distribution", "ship this as a Mac app".
What it does NOT do
- Does not sign or notarize anything (see
references/signing-notarization.mdfor that — it requires a paid Apple Developer account). - Does not create an Xcode project. If the user actually wants a proper Xcode-managed app target, that's a different task — ask before assuming.
Usage
From the repo root (the directory containing Package.swift):
scripts/package_app.shWith no flags it will:
- Auto-detect the app name from the first
.executable(name: "...")product inPackage.swift. swift build -c releasethat product.- Assemble
dist/<App>-<version>-unsigned-<timestamp>/<App>.app. - Stage a DMG with the
.appplus an/Applicationssymlink and build<App>-<version>-unsigned.dmgin the same output directory.
Common flags (scripts/package_app.sh --help for the full list):
| Flag | Purpose |
--app-name NAME | Override auto-detection |
--bundle-id ID | Default is com.example.<lowercased-app-name> — always override this for a real release |
--version STRING | Default 0.1.0 |
--min-os STRING | LSMinimumSystemVersion, default 13.0 |
--menu-bar | Sets LSUIElement=true (no Dock icon / no app switcher entry) |
--icon PATH | Embed a .icns; auto-picked up from assets/<AppName>.icns if present |
--skip-dmg | Build just the .app, skip DMG staging |
Both flags and env vars work (APP_NAME=, BUNDLE_ID=, VERSION=, etc. —
see the script's --help output for the full mapping).
Input rules
Every value that ends up in a path or in Info.plist is validated before the
script touches the filesystem, and the run stops with a clear error: line
if any of them fails:
| Value | Accepted |
--app-name, --product | 1–255 chars of letters, digits, space, ., _, -; starts with a letter or digit; no trailing space or .; never . or ..; no /, \, : or control characters |
--bundle-id | reverse-DNS: two or more dot-separated labels of letters, digits and - (com.example.myapp) |
--version, --min-os | 1–3 dot-separated numbers (1.2.3, 13.0) |
--icon | must be an existing regular file |
Values are then XML-escaped when written into the plist (no sed/awk
interpolation), and the rendered plist is checked with plutil -lint when
plutil is available. If a user wants a display name outside these rules
(non-ASCII, punctuation), keep the bundle name ASCII and localize
CFBundleDisplayName via InfoPlist.strings instead of loosening the check.
Examples
# Menu bar app with a real bundle id and an icon
scripts/package_app.sh --menu-bar --bundle-id com.example.tokenscope \
--version 0.2.0 --icon assets/TokenScope.icns
# Just the .app, no DMG, for quick local testing
scripts/package_app.sh --skip-dmgOutput
A timestamped dist/<App>-<version>-unsigned-<timestamp>/ directory containing
the assembled <App>.app bundle and (unless --skip-dmg) a compressed
<App>-<version>-unsigned.dmg staged with the standard drag-to-Applications
layout.
Detecting the app name from Package.swift
The script greps for the first .executable(name: "X" occurrence. When
briefing a user or writing this by hand, the same rule applies: open
Package.swift, find the products: [ .executable(name: "X", ...) ] entry.
If there are multiple executable products, ask the user which one they mean,
or pass --app-name / --product explicitly (--product matters when the
Swift product name differs from the desired display/bundle name).
When to set LSUIElement (menu-bar-only apps)
Set --menu-bar (→ LSUIElement=true) when the app:
- Lives in the menu bar via
NSStatusItem/MenuBarExtraand has no main window the user is meant to switch to via Cmd-Tab, or - Should not show a Dock icon or appear in the Cmd-Tab app switcher.
Leave it unset (LSUIElement=false, the default) for a normal windowed app
that should appear in the Dock and app switcher as usual. Check the source for
NSStatusBar.system.statusItem or MenuBarExtra in SwiftUI as a strong signal
the app is menu-bar-only.
DMG staging layout
The script stages the DMG contents in a scratch dmg/ folder before calling
hdiutil create -format UDZO:
dmg/
├── YourApp.app (copy of the built bundle)
└── Applications -> /Applications (symlink)This is the standard "drag YourApp.app onto Applications" layout users expect
from a Mac installer DMG. Don't skip the symlink — without it, users have to
manually drag the app to /Applications via Finder navigation instead of a
single drag within the mounted window.
Failure modes
- Missing
NSHighResolutionCapable— omitting this key (or leaving itfalse) makes the app render blurry on Retina displays. The template always sets ittrue; don't remove it when hand-editing a plist. - Forgetting
chmod 755on the binary —cppreserves source permissions, which can be644from some build/copy pipelines, silently producing an app that Finder shows a "no entry" cursor for on launch. The script always doeschmod 755on the copied executable; verify this if the bundling steps are done manually instead of via the script. - Cached icon not updating on rebuild — macOS's icon cache can keep
showing an old icon for an app bundle after replacing its
.icnsorInfo.plist, especially when the app path is reused (same dist folder, overwritten in place). The script mitigates this by giving each build its own timestamped output directory and by runningxattr -cr+touchon the finished bundle. If a stale icon still appears after installing a new build, tell the user to either (a) move/rename the.apponce, or (b) runkillall Finderand/orqlmanage -r cacheand relaunch. CFBundleIdentifierleft as the placeholder default — the script defaults tocom.example.<name>, which is fine for local testing but should always be overridden with a real reverse-DNS identifier before distributing to anyone else (needed later for signing/notarization too).- Building the wrong product — if
Package.swiftdefines multiple executables,--app-namealone builds a product of that same name; use--productwhen the binary/product name differs from the desired app display name. - Running from the wrong directory — the script requires
Package.swiftat the repo root it's given (--repo-root, defaults to cwd). If it errors with "no Package.swift found", cd to the repo root or pass--repo-root. - A build or
hdiutilstep fails partway — the script exits non-zero, deletes the DMG staging folder, and removes the partially assembled timestamped output directory so no half-built.appis left looking distributable. Fix the cause and re-run; nothing needs cleaning by hand. - Distributing the unsigned DMG and getting "damaged" complaints — this
is expected Gatekeeper behavior for unsigned software, not a packaging bug.
Point users to
references/signing-notarization.mdfor both the right-click-to-open workaround and the real signing/notarization path.
Resources
scripts/package_app.sh— the packaging script described above.assets/Info.plist.template— parameterized plist consumed by the script (placeholders:__APP_NAME__,__BUNDLE_ID__,__VERSION__,__MIN_MACOS_VERSION__,__LSUIELEMENT_BOOL__, and an@@ICON_BLOCK@@marker line that expands to theCFBundleIconFilekey/value pair or is dropped entirely when no icon is supplied). Placeholders are filled with XML-escaped, pre-validated values.tests/(repo root) — behavioral tests that run this script against stubbedswift/hdiutil/plutiland check rejected inputs, bundle layout, cleanup, and failure propagation.references/signing-notarization.md— what unsigned distribution means for end users, and the full codesign/notarytool/stapler upgrade path.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

