#!/bin/bash # Installs Takes and what it needs: the app, ffmpeg, Apple's developer tools and an agent (Claude Code, # Codex or pi; Claude Code is installed only when none is there). One line in Terminal: # curl -fsSL https://gettakes.app/install | bash # Takes is not notarized (no paid Apple developer account). A browser download gets a quarantine # flag and macOS blocks the app; a download with curl gets no flag, so Takes opens at once. # Run it again to update. The export copies it to the root of the public repo; the gettakes.app # deploy serves this file from origin/main at /install (2026-10-05). set -euo pipefail # The command from a link with a source (curl -fsSL https://gettakes.app/install/ | bash) gets # a random install code on this line (gettakes.app functions/lib/ref.js, 2026-10-20). Takes sends it # once, with its first update check, so the site can count installs per link. Nothing else. TAKES_INSTALL_TOKEN="" say() { printf '\n\033[1m%s\033[0m\n' "$*"; } fail() { printf '\n%s\n' "$*" >&2; exit 1; } sha256() { shasum -a 256 "$1" | awk '{print $1}'; } [ "$(uname -s)" = Darwin ] || fail "Takes runs on macOS only." [ "$(uname -m)" = arm64 ] || fail "Takes needs a Mac with Apple silicon (M1 or later)." v=$(sw_vers -productVersion) [ "${v%%.*}" -ge 15 ] || fail "Takes needs macOS 15 or later. This Mac has macOS $v." tmp=$(mktemp -d) stage="" lock="" lock_held="" owner_id="" mounted="" cleanup() { status=$? trap - EXIT HUP INT TERM [ -z "$stage" ] || rm -rf "$stage" if [ -n "$lock_held" ] && [ "$(readlink "$lock" 2>/dev/null || true)" = "$owner_id" ]; then rm -f "$lock" fi [ -z "$mounted" ] || hdiutil detach -quiet "$tmp/mnt" 2>/dev/null || true rm -rf "$tmp" exit "$status" } trap cleanup EXIT trap 'exit 1' HUP INT TERM bin="$HOME/.local/bin" mkdir -p "$bin" # 1. The app. say "[1/4] Downloading Takes…" if [ -n "${TAKES_DMG:-}" ]; then cp "$TAKES_DMG" "$tmp/Takes.dmg" # a local build, for a test else curl -fL --progress-bar -o "$tmp/Takes.dmg" https://github.com/marvtub/takes-public/releases/latest/download/Takes.dmg # The release signs the image itself. Authenticate it before a disk-image parser sees it. codesign --verify --strict --all-architectures "$tmp/Takes.dmg" 2>/dev/null \ || fail "The Takes download has an invalid signature. Nothing was installed." codesign --display --extract-certificates="$tmp/takes-signing-" "$tmp/Takes.dmg" 2>/dev/null \ || fail "The Takes download has no publisher certificate. Nothing was installed." takes_cert_sha256=73626d901fb7862b9af4bd4ef373befc587321fc719ae06e3ee2c994ae66e04b [ "$(sha256 "$tmp/takes-signing-0")" = "$takes_cert_sha256" ] \ || fail "The Takes download is not signed by the expected publisher. Nothing was installed." fi hdiutil verify "$tmp/Takes.dmg" >/dev/null \ || fail "The Takes download is damaged. Nothing was installed. Try again later." mounted=1 # detach even when attach partly succeeds before returning an error hdiutil attach -quiet -nobrowse -readonly -mountpoint "$tmp/mnt" "$tmp/Takes.dmg" # A local build is ad-hoc signed; every path still verifies the app before replacing an install. codesign --verify --deep --strict --all-architectures "$tmp/mnt/Takes.app" 2>/dev/null \ || fail "The Takes download has an invalid signature. Nothing was installed." # TAKES_APPS= installs there for a test and leaves a running Takes alone. apps=${TAKES_APPS:-/Applications} [ -w "$apps" ] || { apps="$HOME/Applications"; mkdir -p "$apps"; } started=$(ps -p "$$" -o lstart= 2>/dev/null || true) owner_id="$$|$started" lock="$apps/.takes-install.lock.$$.$(basename "$tmp")" ln -s "$owner_id" "$lock" lock_held=1 # Each installer owns a different atomic symlink (2026-11-06). A live peer always makes this one # stop; stale peers can be removed without replacing a shared path another installer may now own. for peer in "$apps/.takes-install.lock" "$apps"/.takes-install.lock.*; do [ -L "$peer" ] || continue [ "$peer" = "$lock" ] && continue owner=$(readlink "$peer" 2>/dev/null || true) owner_pid=${owner%%|*} owner_started=${owner#*|} if [[ "$owner_pid" =~ ^[0-9]+$ ]] && kill -0 "$owner_pid" 2>/dev/null; then running_started=$(ps -p "$owner_pid" -o lstart= 2>/dev/null || true) if [ -z "$owner_started" ] || [ "$owner_started" = "$running_started" ]; then fail "Another Takes installation is already running. Try again when it finishes." fi fi rm -f "$peer" done # A replacement keeps this backup until the new bundle is in place. Recover one left by a # previous interrupted installer before discarding its other staging directories. for previous in "$apps"/.takes-install.previous.*; do [ -e "$previous" ] || continue if [ -e "$apps/Takes.app" ]; then rm -rf "$previous" else mv "$previous" "$apps/Takes.app" fi done # Only the lock owner may remove staging directories abandoned by SIGKILL or a power loss. for abandoned in "$apps"/.takes-install.*; do [ ! -L "$abandoned" ] && [ -d "$abandoned" ] && rm -rf "$abandoned" done if [ -z "${TAKES_APPS:-}" ] && pgrep -xq -U "$(id -u)" Takes; then say "Quitting Takes to replace it…" osascript -e 'quit app "Takes"' || true for _ in 1 2 3 4 5 6 7 8 9 10; do pgrep -xq -U "$(id -u)" Takes || break; sleep 1; done fi stage=$(mktemp -d "$apps/.takes-install.XXXXXX") incoming="$stage/Takes.app" ditto "$tmp/mnt/Takes.app" "$incoming" || fail "Could not copy Takes. Your installed app was not changed." plist="$incoming/Contents/Info.plist" plistbuddy=${TAKES_PLISTBUDDY:-/usr/libexec/PlistBuddy} [ -f "$plist" ] && [ "$("$plistbuddy" -c 'Print :CFBundleIdentifier' "$plist" 2>/dev/null)" = de.marvinaziz.takes ] && [ "$("$plistbuddy" -c 'Print :CFBundleExecutable' "$plist" 2>/dev/null)" = Takes ] && [ -x "$incoming/Contents/MacOS/Takes" ] || fail "The download does not contain a valid Takes app. Your installed app was not changed." xattr -dr com.apple.quarantine "$incoming" 2>/dev/null || true replace_app() { "${TAKES_OSASCRIPT:-/usr/bin/osascript}" -l JavaScript - "$1" "$2" "$3" <<'JXA' ObjC.import('Foundation') function run(argv) { const manager = $.NSFileManager.defaultManager const incoming = $.NSURL.fileURLWithPath($(argv[0])) const installed = $.NSURL.fileURLWithPath($(argv[1])) const backupName = $.NSURL.fileURLWithPath($(argv[2])).lastPathComponent const error = Ref() let ok if (manager.fileExistsAtPath(installed.path)) { ok = manager.replaceItemAtURLWithItemAtURLBackupItemNameOptionsResultingItemURLError( installed, incoming, backupName, $.NSFileManagerItemReplacementUsingNewMetadataOnly | $.NSFileManagerItemReplacementWithoutDeletingBackupItem, null, error ) } else { ok = manager.moveItemAtURLToURLError(incoming, installed, error) } if (!ok) { const detail = error[0] ? ObjC.unwrap(error[0].localizedDescription) : 'unknown error' throw new Error(detail) } } JXA } # Foundation replaces same-volume items without a point where neither bundle exists. backup="$apps/.takes-install.previous.$$" had_app="" [ -e "$apps/Takes.app" ] && had_app=1 if ! replace_app "$incoming" "$apps/Takes.app" "$backup"; then if [ ! -e "$apps/Takes.app" ] && [ -e "$backup" ]; then mv "$backup" "$apps/Takes.app" fi if [ -n "$had_app" ]; then fail "Could not replace Takes. The previous app was restored." else fail "Could not install Takes. Try again." fi fi rm -rf "$backup" echo "Takes is in $apps." if [[ $TAKES_INSTALL_TOKEN =~ ^[a-km-np-z2-9]{10}$ ]]; then support="$HOME/Library/Application Support/Takes" mkdir -p "$support" && printf '%s\n' "$TAKES_INSTALL_TOKEN" > "$support/install-ref" || true fi # 2. ffmpeg and ffprobe: static builds from ffmpeg.martin-riedl.de (linked from ffmpeg.org), # checked against their SHA-256. Skipped when ffmpeg is already there (Homebrew or other). if command -v ffmpeg >/dev/null || [ -x "$bin/ffmpeg" ] || [ -x /opt/homebrew/bin/ffmpeg ]; then echo "[2/4] ffmpeg is already installed." else say "[2/4] Downloading ffmpeg (about 57 MB)…" for tool in ffmpeg ffprobe; do url=$(curl -fsL -r 0-0 -o /dev/null -w '%{url_effective}' \ "https://ffmpeg.martin-riedl.de/redirect/latest/macos/arm64/release/$tool.zip") curl -fL --progress-bar -o "$tmp/$tool.zip" "$url" want=$(curl -fsSL "$url.sha256" | awk '{print $1}') got=$(shasum -a 256 "$tmp/$tool.zip" | awk '{print $1}') [ -n "$want" ] && [ "$want" = "$got" ] || fail "The $tool download does not match its checksum. Try again later." ditto -x -k "$tmp/$tool.zip" "$tmp/$tool" install -m 755 "$tmp/$tool/$tool" "$bin/$tool" done echo "ffmpeg is in $bin." fi # 3. Apple's developer tools: the takes MCP server, which links Takes to your agents, runs on # their Python. Apple's dialog installs them in a few minutes; Takes connects the agents after. if xcode-select -p >/dev/null 2>&1; then echo "[3/4] Apple's developer tools are installed." else say "[3/4] Installing Apple's developer tools. Click Install in Apple's dialog; it goes on in the background." xcode-select --install 2>/dev/null || echo "Install them later: open Takes and click Finish setup." fi # 4. An agent: Claude Code, Codex or pi. One signed-in agent is enough. Claude Code comes, with # Anthropic's own installer, only when the Mac has none of them (2026-10-12). agent() { command -v "$1" 2>/dev/null || { [ -x "$bin/$1" ] && echo "$bin/$1"; } || true; } signed_in() { # $1: name, $2: path case "$1" in claude) "$2" auth status 2>/dev/null | grep -q '"loggedIn": *true' ;; codex) "$2" login status 2>&1 | grep -qi '^logged in' ;; pi) d=${PI_CODING_AGENT_DIR:-$HOME/.pi/agent} /usr/bin/python3 -c 'import json,sys; d=sys.argv[1] def o(n): try: return json.load(open(d+"/"+n)) except Exception: return {} sys.exit(0 if len(o("auth.json")) + len(o("models.json").get("providers", {})) else 1)' "$d" 2>/dev/null ;; esac } name() { case "$1" in claude) echo "Claude Code" ;; codex) echo Codex ;; pi) echo pi ;; esac; } here=() ready="" for a in claude codex pi; do p=$(agent "$a") [ -n "$p" ] || continue here+=("$a") [ -z "$ready" ] && signed_in "$a" "$p" && ready=$a done if [ -n "$ready" ]; then echo "[4/4] $(name "$ready") is installed and signed in." elif [ ${#here[@]} -gt 0 ]; then first=${here[0]}; p=$(agent "$first") echo "[4/4] $(name "$first") is installed." case "$first" in claude) say "Sign in to Claude Code. Your browser opens; come back here when you are done." "$p" auth login /dev/null || {" print " rm -f \"$binary_path\"" print " echo \"The Claude Code download is not signed by Anthropic. Nothing was run. Try again later.\" >&2" print " exit 1" print "}" inserted++ } END { if (inserted != 1) exit 1 } ' "$tmp/claude-install.sh" > "$tmp/claude-install-verified.sh" \ || fail "The Claude Code installer has an unexpected format. Nothing was run. Try again later." /bin/bash "$tmp/claude-install-verified.sh" claude="$bin/claude" # Confirm the launcher still points to authenticated code after installation. codesign --verify --strict --all-architectures \ -R='identifier "com.anthropic.claude-code" and anchor apple generic and certificate leaf[subject.OU] = "Q6L2SF6YDW"' \ "$claude" 2>/dev/null \ || fail "The Claude Code download is not signed by Anthropic. Nothing was run. Try again later." say "Sign in to Claude Code. Your browser opens; come back here when you are done." "$claude" auth login