Open a local file or directory on macOS using open. Supports specifying an app, URL scheme deep linking, and error recovery.
Usage
/open-file <path> [app]
- If no path is provided, infer from conversation context (e.g., a file just created or discussed).
- If an app is mentioned (e.g., "in Obsidian"), use
open -aor the app's URL scheme.
Workflow
- Resolve the path. Make it absolute. If relative, resolve against cwd.
-
Verify the target exists:
[ -e '<path>' ] && echo "EXISTS" || echo "NOT_FOUND"If not found, tell the user and stop.
-
Open:
With a specific app:
open -a '<App Name>' '<path>'With the default app:
open '<path>' -
Handle
procNotFounderror. Ifopenfails because the app isn't running:open -a '<App Name>' && sleep 3 && open -a '<App Name>' '<path>'Launch the app first, wait for it to initialize, then retry.
-
Confirm to the user that the file was opened.
URL Scheme Deep Linking
Use URL schemes when the user wants to jump to a specific item within an app, not just open a file.
| App | Command |
|---|---|
| Obsidian | open -a "Obsidian" && sleep 3 && open 'obsidian://open?vault=<vault>&file=<url-encoded-path>' |
| VS Code | code '<path>' or open 'vscode://file/<absolute-path>' |
URL-encode path components — especially emoji, CJK characters, and spaces.
Notes
- Always single-quote paths to handle spaces and special characters
open '<directory>'opens in Finderopen -aboth launches the app (if needed) and opens the file in one step — the two-step launch-then-open is only needed for URL scheme calls where the app must be running first