Get the FREE Ultimate OpenClaw Setup Guide →

applescript-open-app

npx machina-cli add skill IvanCampos/agents/applescript-open-app --openclaw
Files (1)
SKILL.md
2.0 KB

AppleScript Open App

Overview

Use a performance-first launch path for opening apps (open -a) with AppleScript fallback for compatibility, and AppleScript for graceful quits.

Quick Start

  • Prefer scripts/open_app.sh for a reliable one-liner interface.
  • Prefer scripts/quit_app.sh for quitting an app.
  • Pass the app name exactly as it appears in Finder (for example, "Xcode", "Safari", "Final Cut Pro").
scripts/open_app.sh "Safari"
scripts/quit_app.sh "Discord"

Tasks

Open an app by name

  • Run scripts/open_app.sh "<App Name>".
  • The script uses fast LaunchServices activation first, then falls back to AppleScript activation only when needed.
  • If the app is not installed, surface the AppleScript error and ask for the correct name.

Open a new instance (only when asked)

  • Use open -na "<App Name>" only if the user explicitly requests a new instance.
  • Otherwise use AppleScript activation.

Quit an app by name

  • Run scripts/quit_app.sh "<App Name>".
  • The script checks whether the app is running before sending quit, avoiding slow error-path exits for already-closed apps.
  • If the app is not installed, surface the AppleScript error and ask for the correct name.

Handle ambiguous names

  • If multiple apps share a name, ask for the exact display name or bundle id.
  • If a bundle id is provided, use AppleScript with application id.
osascript -e 'tell application id "com.apple.Safari" to activate'

AppleScript snippet

osascript -e 'tell application "Safari" to activate'
osascript -e 'tell application "Safari" to quit'

Resources

scripts/

  • open_app.sh: Fast open -a launch/activate with AppleScript fallback.
  • quit_app.sh: Graceful AppleScript quit with running-state guard.

Source

git clone https://github.com/IvanCampos/agents/blob/main/skills/applescript-open-app/SKILL.mdView on GitHub

Overview

This skill lets you open, launch, activate, or quit macOS apps by name using AppleScript or osascript. It prioritizes a fast open path with open -a, falls back to AppleScript for compatibility, and uses graceful quitting logic to avoid errors.

How This Skill Works

It first tries a fast LaunchServices path via open -a to activate the app. If needed, it falls back to osascript commands to tell the app to activate or quit. It includes safeguards like checking if an app is running before quitting and handles ambiguous names by prompting for a precise display name or bundle id.

When to Use It

  • User asks to open or launch an app by name, such as 'open Xcode' or 'start Safari'.
  • User asks to quit an app, such as 'quit Discord' or 'close Mail'.
  • User explicitly requests a new instance of an app, e.g., 'open a new instance of Chrome'.
  • Multiple apps share the same name and disambiguation is required (display name or bundle id).
  • AppleScript-based control is required or a reliable, script-driven quit/open workflow is needed.

Quick Start

  1. Step 1: Use scripts/open_app.sh "<App Name>" to open/activate an app with a fast path and AppleScript fallback.
  2. Step 2: Use scripts/quit_app.sh "<App Name>" to quit gracefully, with a running-state check.
  3. Step 3: If a new instance is required, use open -na "<App Name>" and confirm the user’s explicit request.

Best Practices

  • Prefer the fast open path (open -a) first for reliability and speed.
  • Use AppleScript activation only when the fast path isn’t sufficient or for compatibility.
  • Surface clear AppleScript errors when an app isn’t installed or the name is incorrect.
  • Verify the exact display name in Finder to avoid misfires.
  • Handle ambiguous names by requesting the exact display name or bundle id, or by using an app id.

Example Use Cases

  • scripts/open_app.sh "Safari" to bring Safari to the foreground quickly.
  • scripts/quit_app.sh "Discord" to gracefully quit Discord if it’s running.
  • osascript -e 'tell application "Safari" to activate' to ensure Safari is frontmost.
  • open -na "Notes" to force a new instance when explicitly requested.
  • osascript -e 'tell application id "com.apple.Safari" to activate' when targeting a specific bundle.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers