Get Battery Status
get_battery_statusRetrieve the current battery percentage, charging state, power source, and estimated time remaining on macOS.
Instructions
Get battery percentage, charging state, power source, and estimated time rema...
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/system/scripts.ts:235-261 (handler)The actual JXA script that executes the battery status logic. It uses pmset -g batt via shell command, parses the output to extract battery percentage, charging state, power source, and time remaining.
export function getBatteryStatusScript(): string { return ` const app = Application.currentApplication(); app.includeStandardAdditions = true; const output = app.doShellScript('pmset -g batt'); const lines = output.split('\\n'); let percentage = null; let charging = false; let timeRemaining = null; let source = null; for (const line of lines) { if (line.indexOf('AC Power') !== -1) source = 'AC Power'; if (line.indexOf('Battery Power') !== -1) source = 'Battery Power'; const pctMatch = line.match(/(\\d+)%/); if (pctMatch) percentage = parseInt(pctMatch[1]); if (line.indexOf('charging') !== -1 && line.indexOf('discharging') === -1 && line.indexOf('not charging') === -1) charging = true; const timeMatch = line.match(/(\\d+:\\d+) remaining/); if (timeMatch) timeRemaining = timeMatch[1]; } JSON.stringify({ percentage: percentage, charging: charging, source: source, timeRemaining: timeRemaining, raw: output }); `; - src/system/tools.ts:399-419 (registration)Registers the 'get_battery_status' tool on the MCP server with title 'Get Battery Status', description, input/output schemas, and a handler that runs the getBatteryStatusScript via JXA.
server.registerTool( "get_battery_status", { title: "Get Battery Status", description: "Get battery percentage, charging state, power source, and estimated time remaining.", inputSchema: {}, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, async () => { try { return ok(await runJxa(getBatteryStatusScript())); } catch (e) { return errJxaFor("get battery status", e); } }, ); - src/shared/tool-links.ts:146-149 (helper)Tool link entry: get_system_info suggests get_battery_status as a follow-up action.
get_system_info: [ { tool: "list_running_apps", description: "See running apps" }, { tool: "get_battery_status", description: "Check battery" }, ], - docs/app.js:234-234 (helper)Documentation listing 'get_battery_status' as a read-type tool with description 'Battery info'.
{ name: 'get_battery_status', desc: 'Battery info', type: 'read' }, - src/cross/prompts.ts:853-853 (helper)Korean prompt referencing get_battery_status for checking battery level.
- get_battery_status로 배터리 잔량 확인