Skip to content

IvanCampos/agents / skills/launchd-non-apple-jobs

launchd-non-apple-jobs

Unverified

List launchd jobs that are not from Apple and create user launchd jobs. Use when the user says "show me my jobs", "show my launchd jobs", asks for non-Apple launchd jobs, or wants to create a one-time or recurring launchd job.

FileKindSize
SKILL.mdskill md1.8 KB
agents/openai.yamlconfig202 B
scripts/create_job.shexecutablescript6.7 KB
scripts/delete_job.shexecutablescript1.5 KB
scripts/show_jobs.shexecutablescript132 B

scripts/create_job.sh

View on GitHub
#!/usr/bin/env bash
set -euo pipefail

usage() {
  cat <<'USAGE'
Usage:
  create_job.sh --label <label> --command <command> --once "YYYY-MM-DD HH:MM"
  create_job.sh --label <label> --command <command> --daily "HH:MM"
  create_job.sh --label <label> --command <command> --weekly "Mon@HH:MM"
  create_job.sh --label <label> --command <command> --monthly "DD@HH:MM"
  create_job.sh --label <label> --command <command> --interval <seconds>

Options:
  --label     LaunchAgent label (e.g., com.example.myjob)
  --command   Command to run (quoted string)
  --once      One-time schedule (local time)
  --daily     Daily time (HH:MM)
  --weekly    Weekly time (Day@HH:MM, Day = Sun/Mon/Tue/Wed/Thu/Fri/Sat)
  --monthly   Monthly time (DD@HH:MM, DD = 1-31)
  --interval  StartInterval in seconds
  --dry-run   Print plist (and wrapper for --once) without writing/loading
USAGE
}

xml_escape() {
  local s="$1"
  s=${s//&/&amp;}
  s=${s//</&lt;}
  s=${s//>/&gt;}
  s=${s//\"/&quot;}
  s=${s//\'/&apos;}
  printf '%s' "$s"
}

label=""
command=""
mode=""
value=""
dry_run=0

while [[ $# -gt 0 ]]; do
  case "$1" in
    --label) label="$2"; shift 2 ;;
    --command) command="$2"; shift 2 ;;
    --once|--daily|--weekly|--monthly|--interval)
      mode="$1"; value="$2"; shift 2 ;;
    --dry-run) dry_run=1; shift ;;
    -h|--help) usage; exit 0 ;;
    *) echo "Unknown arg: $1" >&2; usage; exit 2 ;;
  esac
done

if [[ -z "$label" || -z "$command" || -z "$mode" || -z "$value" ]]; then
  echo "Missing required arguments." >&2
  usage
  exit 2
fi

launch_agents_dir="${HOME}/Library/LaunchAgents"
logs_dir="${HOME}/Library/Logs/launchd"
plist_path="${launch_agents_dir}/${label}.plist"
wrapper_path="${launch_agents_dir}/${label}-once.sh"

schedule_xml=""

parse_time() {
  local t="$1"
  local h m
  IFS=':' read -r h m <<<"$t"
  if [[ -z "$h" || -z "$m" ]]; then
    echo "Invalid time: $t" >&2
    exit 2
  fi
  echo "$h" "$m"
}

weekday_to_int() {
  local day
  day="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
  case "$day" in
    sun) echo 0 ;;
    mon) echo 1 ;;
    tue) echo 2 ;;
    wed) echo 3 ;;
    thu) echo 4 ;;
    fri) echo 5 ;;
    sat) echo 6 ;;
    *) echo "Invalid weekday: $1" >&2; exit 2 ;;
  esac
}

case "$mode" in
  --once)
    # Local time, month/day/hour/minute
    if ! parts=$(date -j -f "%Y-%m-%d %H:%M" "$value" "+%m %d %H %M" 2>/dev/null); then
      echo "Invalid --once value: $value" >&2
      exit 2
    fi
    read -r month day hour minute <<<"$parts"
    schedule_xml=$(cat <<XML
    <key>StartCalendarInterval</key>
    <dict>
      <key>Month</key><integer>${month#0}</integer>
      <key>Day</key><integer>${day#0}</integer>
      <key>Hour</key><integer>${hour#0}</integer>
      <key>Minute</key><integer>${minute#0}</integer>
    </dict>
XML
)
    ;;
  --daily)
    read -r hour minute <<<"$(parse_time "$value")"
    schedule_xml=$(cat <<XML
    <key>StartCalendarInterval</key>
    <dict>
      <key>Hour</key><integer>${hour#0}</integer>
      <key>Minute</key><integer>${minute#0}</integer>
    </dict>
XML
)
    ;;
  --weekly)
    day_part="${value%@*}"
    time_part="${value#*@}"
    read -r hour minute <<<"$(parse_time "$time_part")"
    weekday=$(weekday_to_int "$day_part")
    schedule_xml=$(cat <<XML
    <key>StartCalendarInterval</key>
    <dict>
      <key>Weekday</key><integer>${weekday}</integer>
      <key>Hour</key><integer>${hour#0}</integer>
      <key>Minute</key><integer>${minute#0}</integer>
    </dict>
XML
)
    ;;
  --monthly)
    day_part="${value%@*}"
    time_part="${value#*@}"
    read -r hour minute <<<"$(parse_time "$time_part")"
    if ! [[ "$day_part" =~ ^[0-9]{1,2}$ ]] || ((day_part < 1 || day_part > 31)); then
      echo "Invalid day of month: $day_part" >&2
      exit 2
    fi
    schedule_xml=$(cat <<XML
    <key>StartCalendarInterval</key>
    <dict>
      <key>Day</key><integer>${day_part#0}</integer>
      <key>Hour</key><integer>${hour#0}</integer>
      <key>Minute</key><integer>${minute#0}</integer>
    </dict>
XML
)
    ;;
  --interval)
    if ! [[ "$value" =~ ^[0-9]+$ ]]; then
      echo "Invalid interval seconds: $value" >&2
      exit 2
    fi
    schedule_xml=$(cat <<XML
    <key>StartInterval</key>
    <integer>${value}</integer>
XML
)
    ;;
  *)
    echo "Unsupported mode: $mode" >&2
    exit 2
    ;;
esac

label_xml=$(xml_escape "$label")
command_xml=$(xml_escape "$command")
stdout_path=$(xml_escape "${logs_dir}/${label}.out.log")
stderr_path=$(xml_escape "${logs_dir}/${label}.err.log")
trash_bin="$(command -v trash || true)"

program_args_xml=""

if [[ "$mode" == "--once" ]]; then
  wrapper_content=$(cat <<'WRAP'
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -lt 1 ]]; then
  echo "Missing command" >&2
  exit 2
fi

/bin/bash -lc "$1"
/bin/launchctl bootout "gui/$(/usr/bin/id -u)" "__PLIST_PATH__" || true
trash_bin="__TRASH_BIN__"
if [[ -n "$trash_bin" && -x "$trash_bin" ]]; then
  "$trash_bin" "__PLIST_PATH__" "__WRAPPER_PATH__" || true
else
  echo "trash not found; leaving launchd files in place" >&2
fi
WRAP
)
  wrapper_content="${wrapper_content//__PLIST_PATH__/${plist_path}}"
  wrapper_content="${wrapper_content//__WRAPPER_PATH__/${wrapper_path}}"
  wrapper_content="${wrapper_content//__TRASH_BIN__/${trash_bin}}"
  if [[ $dry_run -eq 0 ]]; then
    mkdir -p "$launch_agents_dir" "$logs_dir"
    printf '%s\n' "$wrapper_content" > "$wrapper_path"
    chmod +x "$wrapper_path"
  fi
  wrapper_xml=$(xml_escape "$wrapper_path")
  command_xml=$(xml_escape "$command")
  program_args_xml=$(cat <<XML
    <key>ProgramArguments</key>
    <array>
      <string>${wrapper_xml}</string>
      <string>${command_xml}</string>
    </array>
XML
)
else
  program_args_xml=$(cat <<XML
    <key>ProgramArguments</key>
    <array>
      <string>/bin/bash</string>
      <string>-lc</string>
      <string>${command_xml}</string>
    </array>
XML
)
fi

plist_xml=$(cat <<XML
<?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>Label</key><string>${label_xml}</string>
${program_args_xml}
${schedule_xml}
  <key>StandardOutPath</key><string>${stdout_path}</string>
  <key>StandardErrorPath</key><string>${stderr_path}</string>
</dict>
</plist>
XML
)

if [[ $dry_run -eq 1 ]]; then
  echo "[DRY RUN] Would write: ${plist_path}" >&2
  if [[ "$mode" == "--once" ]]; then
    echo "[DRY RUN] Would write: ${wrapper_path}" >&2
    echo "[DRY RUN] Wrapper contents:" >&2
    echo "$wrapper_content" >&2
  fi
  echo "$plist_xml"
  exit 0
fi

mkdir -p "$launch_agents_dir" "$logs_dir"
printf '%s\n' "$plist_xml" > "$plist_path"

# Reload the job
launchctl bootout "gui/${UID}" "$plist_path" >/dev/null 2>&1 || true
launchctl bootstrap "gui/${UID}" "$plist_path"

echo "Created and loaded: $plist_path"
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall