Skip to content
macos-launchd-service logo

macOS launchd Service Setup

macos-launchd-service

Set up macOS launchd service for auto-starting Python applications

SKILL.md

Full skill instructions

macOS launchd Service Setup

Generate complete launchd service infrastructure for Python applications on macOS.

What This Skill Creates

launchd/
├── install.sh                          # Automated service installer
├── uninstall.sh                        # Service uninstaller
├── {project}.plist.template           # Service configuration
dev.sh                                  # Development mode script
view-logs.sh                           # Log viewing helper

When to Use This Skill

  • Web services: FastAPI, Flask apps that should auto-start
  • Background services: Daemons, periodic tasks
  • Development servers: Local services you want always running

Before Running

Requirements:

  • macOS 10.10+ with launchd
  • Python project with uv and .venv
  • pyproject.toml with [project.scripts] defining a CLI command

Check pyproject.toml:

[project.scripts]
yourapp = "yourapp.cli:main"

IMPORTANT - Replacing Existing Setup:

If the project already has launchd/ directory or existing scripts:

  • ALWAYS use the parameters provided by the user
  • DO NOT read values from existing files
  • The user wants to replace with NEW values, not keep old ones
  • Overwrite existing files with the new parameter values

Step-by-Step Process

1. Gather Information from User

Ask the user for these parameters (use AskUserQuestion if needed):

  • Domain (e.g., "dev.pborenstein", "com.pborenstein") - Reverse domain notation for service label
    • Default suggestion: dev.{username} (e.g., "dev.philip")
    • Best practice: Use owned domain (e.g., "dev.pborenstein" if you own pborenstein.dev)
  • Project name (e.g., "temoa", "apantli") - lowercase, no spaces
  • Module name (e.g., "temoa", "apantli") - Python import name
  • Port number (e.g., 4001, 4000) - unique port for this service
  • CLI command (e.g., "temoa server", "python3 -m apantli.server")
  • Dev command (e.g., "temoa server --reload", "python3 -m apantli.server --reload")
  • Process name (e.g., "temoa server", "apantli.server") - for detecting running processes

Use these exact values provided by the user - do not infer from existing files.

2. Suggest Defaults from pyproject.toml (Optional)

Only if the user hasn't provided values, you may suggest defaults from pyproject.toml:

# Suggest project name
grep "^name" pyproject.toml

# Suggest CLI command from [project.scripts]
grep -A 5 "\[project.scripts\]" pyproject.toml

But always use what the user explicitly provides.

3. Generate launchd Directory

Create launchd/ directory:

mkdir -p launchd

4. Generate Files from Templates

For each template in skills/​macos-launchd-service/​templates/, perform substitutions:

Substitution variables:

User-provided parameters (use values from step 1):

  • {{DOMAIN}} - Reverse domain notation (e.g., "dev.pborenstein", "com.pborenstein")
  • {{PROJECT_NAME}} - Project name (e.g., "temoa")
  • {{MODULE_NAME}} - Python module name for import check
  • {{PORT}} - Port number
  • {{CLI_COMMAND}} - Full CLI command as plist array elements
  • {{DEV_COMMAND}} - Development mode command
  • {{PROCESS_NAME}} - Process name for pkill/​pgrep

Auto-detected variables (these are filled in by install.sh at runtime):

  • {{HOME}} - User's home directory
  • {{PROJECT_DIR}} - Absolute path to project directory
  • {{VENV_PYTHON}} - Path to venv Python interpreter
  • {{VENV_BIN}} - Path to venv bin directory

CLI_COMMAND special handling:

Must be converted to plist array format:

Input: "temoa server --host 0.0.0.0 --port 4001"

Output:
        <string>{{VENV_BIN}}/​temoa</​string>
        <string>server</​string>
        <string>--host</​string>
        <string>0.0.0.0</​string>
        <string>--port</​string>
        <string>4001</​string>

5. Generated Files

install.sh (from install.sh.template):

  • Auto-detects environment (username, paths, venv)
  • Validates venv and module are installed
  • Generates service plist from template
  • Installs and loads service
  • Shows access information and management commands

uninstall.sh (from uninstall.sh.template):

  • Checks if service exists
  • Shows what will be removed
  • Asks for confirmation
  • Stops running service
  • Removes plist file
  • Confirms uninstall complete

{project}.plist.template (from service.plist.template):

  • Service configuration with substitution placeholders
  • Used by install.sh to generate final plist
  • Configured with RunAtLoad, KeepAlive for production

dev.sh (from dev.sh.template):

  • Stops launchd service if running
  • Runs app with auto-reload for development
  • Uses caffeinate to prevent sleep
  • Offers to restore service on exit

view-logs.sh (from view-logs.sh.template):

  • Modes: app logs, errors, or all
  • Uses tail -f for live viewing
  • Logs location: ~/​Library/​Logs/​{project}.log

6. Make Scripts Executable

chmod +x launchd/​install.sh
chmod +x launchd/​uninstall.sh
chmod +x dev.sh
chmod +x view-logs.sh

7. Provide Next Steps

After generation, tell the user:

✓ Generated launchd service structure

Next steps:
1. Review generated files in launchd/
2. Run: ./​launchd/​install.sh
3. Access your service at: http://localhost:{PORT}
4. View logs: ./​view-logs.sh
5. Development mode: ./​dev.sh

Service will auto-start on login and auto-restart on crash.

Manage service:
  Stop:    launchctl unload ~/​Library/​LaunchAgents/​{DOMAIN}.{project}.plist
  Start:   launchctl load ~/​Library/​LaunchAgents/​{DOMAIN}.{project}.plist
  Status:  launchctl list | grep {project}

Example: temoa

Input parameters:

  • Domain: dev.pborenstein
  • Project name: temoa
  • Module name: temoa
  • Port: 4001
  • CLI command: temoa server --host 0.0.0.0 --port 4001 --log-level info
  • Dev command: temoa server --reload
  • Process name: temoa server

Generated CLI_COMMAND for plist:

    <array>
        <string>{{VENV_BIN}}/​temoa</​string>
        <string>server</​string>
        <string>--host</​string>
        <string>0.0.0.0</​string>
        <string>--port</​string>
        <string>4001</​string>
        <string>--log-level</​string>
        <string>info</​string>
    </​array>

Implementation Notes

Reading templates:

Templates are in skills/​macos-launchd-service/​templates/:

  • install.sh.template
  • uninstall.sh.template
  • service.plist.template
  • dev.sh.template
  • view-logs.sh.template

Writing generated files:

  • launchd/​install.sh
  • launchd/​uninstall.sh
  • launchd/​{PROJECT_NAME}.plist.template
  • dev.sh
  • view-logs.sh

String substitution:

Simple replace all instances of each {{VARIABLE}} with its value.

CLI_COMMAND conversion:

Split on spaces, wrap each token in <string>TOKEN</​string> with proper indentation.

Validation

After generation, verify:

  • All 5 files created (install.sh, uninstall.sh, plist.template, dev.sh, view-logs.sh)
  • Scripts are executable
  • No leftover {{VARIABLES}} in files
  • CLI_COMMAND properly formatted as plist array

Common Issues

Port conflicts: Use lsof -i :{PORT} to check if port is available

Module not found: User needs to run uv sync first

Permission errors: Ensure ~/​Library/​LaunchAgents exists

See Also

  • README.md - Detailed usage guide
  • Example implementations: temoa, apantli in nahuatl-projects

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View