AgentSkillsCN

applescript-open-app

通过AppleScript或osascript,根据应用名称打开、启动、激活或退出macOS应用。当用户请求打开/启动/激活/退出某款应用(如“打开Xcode”“退出Discord”),或需要基于AppleScript的应用控制时,可使用此功能。

SKILL.md
--- frontmatter
name: applescript-open-app
description: Open, launch, activate, or quit macOS apps by name using AppleScript or osascript. Use when the user asks to open/launch/activate/quit an app ("open Xcode", "quit Discord"), or when AppleScript-based app control is required.

AppleScript Open App

Overview

Use AppleScript (via osascript) to activate or quit a macOS application by its display name.

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").
bash
scripts/open_app.sh "Safari"
bash
scripts/quit_app.sh "Discord"

Tasks

Open an app by name

  • Run scripts/open_app.sh "<App Name>".
  • 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>".
  • If the app is not installed or already quit, 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.
bash
osascript -e 'tell application id "com.apple.Safari" to activate'

AppleScript snippet

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

Resources

scripts/

  • open_app.sh: Shell wrapper that passes the app name to AppleScript via osascript.
  • quit_app.sh: Shell wrapper that quits the app via osascript.