open_with_app
Open files or folders directly with a specified application on macOS, streamlining access and improving workflow efficiency.
Instructions
Open a file or folder with a specific application
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appName | Yes | ||
| filePath | Yes |
Implementation Reference
- utils/index.ts:30-43 (handler)Implements the core logic to open a file with a specified macOS application using the 'open -a' command.export async function openWithApp( appName: string, filePath: string ): Promise<boolean> { try { const fullAppName = appName.endsWith(".app") ? appName : `${appName}.app`; const appPath = join("/Applications", fullAppName); await execAsync(`open -a "${appPath}" "${filePath}"`); return true; } catch (error) { console.error("Error opening file with application:", error); return false; } }
- tools.ts:14-17 (schema)Zod schema for input validation of the open_with_app tool.export const OpenWithAppInputSchema = { appName: z.string(), filePath: z.string(), };
- tools.ts:76-101 (registration)Registers the open_with_app tool with name, description, annotations, schema reference, and callback that invokes the handler.const openWithAppConfig: ToolConfig<typeof OpenWithAppInputSchema> = { name: "open_with_app", description: "Open a file or folder with a specific application", annotations: { title: "用應用程式開啟檔案", readOnlyHint: false, // 會修改系統狀態 destructiveHint: false, // 不執行破壞性操作 idempotentHint: false, // 重複開啟可能有不同結果 openWorldHint: true, // 與外部應用程式和檔案互動 }, schema: OpenWithAppInputSchema, cb: async (args) => { const success = await openWithApp(args.appName, args.filePath); const toolResult: CallToolResult = { content: [ { type: "text", text: success ? "File opened successfully" : "Failed to open file with application", }, ], }; return toolResult; }, };