#!/bin/sh # Builds Orgstar.app in .build/app from the release binary, signed ad hoc for local use. The # icon is drawn by scripts/make-icon.swift. # Usage: scripts/build-app.sh [version] set -eu cd "$(dirname "$0")/.." version="${1:-0.1.0}" app=".build/app/Orgstar.app" swift build -c release --product Orgstar swift build -c release --product OrgstarQuickLook swift build -c release --product OrgstarSpotlight binary="$(swift build -c release --show-bin-path)/Orgstar" rm -rf "$app" mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" cp "$binary" "$app/Contents/MacOS/Orgstar" iconset="$(mktemp -d)/AppIcon.iconset" swift scripts/make-icon.swift "$iconset" iconutil -c icns "$iconset" -o "$app/Contents/Resources/AppIcon.icns" rm -rf "$(dirname "$iconset")" cat > "$app/Contents/Info.plist" < CFBundleIdentifier sh.krz.orgstar CFBundleName Orgstar CFBundleDisplayName Orgstar CFBundleExecutable Orgstar CFBundlePackageType APPL CFBundleIconFile AppIcon UTImportedTypeDeclarations UTTypeIdentifier org.orgmode.org UTTypeDescription Org document UTTypeConformsTo public.plain-text UTTypeTagSpecification public.filename-extension orgorg_archive CFBundleDocumentTypes CFBundleTypeName Org document CFBundleTypeRole Editor LSHandlerRank Default LSItemContentTypes org.orgmode.org CFBundleTypeName Text CFBundleTypeRole Editor LSHandlerRank Alternate LSItemContentTypes public.plain-text CFBundleURLTypes CFBundleURLName org-protocol CFBundleURLSchemes org-protocol CFBundleShortVersionString ${version} CFBundleVersion ${version} LSMinimumSystemVersion 26.0 LSApplicationCategoryType public.app-category.productivity NSHighResolutionCapable NSPrincipalClass NSApplication EOF # App Intents metadata for Shortcuts, from the constant values Swift Build extracted; SwiftPM # doesn't run this step itself. toolchain="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain" objects=".build/out/Intermediates.noindex/Orgstar.build/Release/Orgstar-p.build/Objects-normal/$(uname -m)" work="$(mktemp -d)" echo "$PWD/$objects/Orgstar-primary.swiftconstvalues" > "$work/constvalues.txt" "$toolchain/usr/bin/appintentsmetadataprocessor" --toolchain-dir "$toolchain" --module-name Orgstar \ --sdk-root "$(xcrun --sdk macosx --show-sdk-path)" --xcode-version "$(xcodebuild -version | awk '/Build version/ {print $3}')" \ --platform-family macOS --deployment-target 26.0 --bundle-identifier sh.krz.orgstar \ --target-triple "$(uname -m)-apple-macos26.0" --binary-file "$binary" --source-file-list "$objects/Orgstar.SwiftFileList" \ --swift-const-vals-list "$work/constvalues.txt" --output "$app/Contents/Resources" --force > /dev/null 2>&1 rm -rf "$work" # App extensions: Quick Look previews and the Spotlight importer. They run sandboxed. appex() { # name, extension point, principal class, attributes dir="$app/Contents/PlugIns/$1.appex/Contents" mkdir -p "$dir/MacOS" cp "$(dirname "$binary")/$1" "$dir/MacOS/$1" cat > "$dir/Info.plist" < CFBundleIdentifier sh.krz.orgstar.$(echo "$1" | sed 's/^Orgstar//' | tr 'A-Z' 'a-z') CFBundleName $1 CFBundleExecutable $1 CFBundlePackageType XPC! CFBundleShortVersionString ${version} CFBundleVersion ${version} LSMinimumSystemVersion 26.0 NSExtension NSExtensionPointIdentifier $2 NSExtensionPrincipalClass $3 NSExtensionAttributes $4 PLIST cat > "$work/sandbox.entitlements" < com.apple.security.app-sandbox PLIST codesign --force --sign - --entitlements "$work/sandbox.entitlements" "$app/Contents/PlugIns/$1.appex" } work="$(mktemp -d)" appex OrgstarQuickLook com.apple.quicklook.preview PreviewProvider \ "QLSupportedContentTypesorg.orgmode.orgQLIsDataBasedPreview" appex OrgstarSpotlight com.apple.spotlight.import ImportExtension \ "CSSupportedContentTypesorg.orgmode.org" rm -rf "$work" codesign --force --sign - "$app" echo "$app"