fix-event-times
Corrects calendar events that are mistakenly scheduled at midnight by adjusting them to proper daytime hours in your macOS Calendar.
Instructions
修正错误的事件时间(从凌晨修正到正确时间)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| calendar | Yes | 日历名称 | 工作 |
| datePattern | Yes | 目标日期模式,如:2025-07-10 | |
| corrections | Yes | 时间修正列表 |
Implementation Reference
- macos-calendar-mcp-sdk.js:612-674 (handler)The main handler function that implements the logic for the 'fix-event-times' tool. It processes each correction by keyword, constructs new start/end datetimes using the provided datePattern, generates AppleScript to find matching events in the calendar, and updates their times using osascript.async fixEventTimes(args) { const { calendar = '工作', datePattern, corrections } = args; const results = []; let successCount = 0; let failCount = 0; for (const correction of corrections) { try { // 构建正确的日期时间 const newStartDateTime = `${datePattern} ${correction.newStartTime}`; const newEndDateTime = `${datePattern} ${correction.newEndTime}`; const startInfo = this.formatDateForAppleScript(newStartDateTime); const endInfo = this.formatDateForAppleScript(newEndDateTime); const startTimeScript = this.generateTimeScript(startInfo, 'newStartTime'); const endTimeScript = this.generateTimeScript(endInfo, 'newEndTime'); const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" set allEvents to every event of theCalendar set fixedCount to 0 ${startTimeScript} ${endTimeScript} repeat with anEvent in allEvents if (summary of anEvent) contains "${correction.keyword}" then set start date of anEvent to newStartTime set end date of anEvent to newEndTime set fixedCount to fixedCount + 1 end if end repeat return fixedCount end tell `; const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); const fixedCount = parseInt(result.trim()) || 0; if (fixedCount > 0) { results.push(`✅ "${correction.keyword}" - 修正了 ${fixedCount} 个事件到 ${correction.newStartTime}-${correction.newEndTime}`); successCount += fixedCount; } else { results.push(`⚠️ "${correction.keyword}" - 未找到匹配的事件`); } } catch (error) { results.push(`❌ "${correction.keyword}" - 修正失败: ${error.message}`); failCount++; } } return { content: [ { type: 'text', text: `🔧 时间修正结果:\n成功修正: ${successCount}个事件\n失败: ${failCount}个修正\n\n详细结果:\n${results.join('\n')}`, }, ], }; }
- macos-calendar-mcp-sdk.js:194-222 (schema)The input schema defining the parameters for the 'fix-event-times' tool: calendar, datePattern, and corrections array with keyword and new times.inputSchema: { type: 'object', properties: { calendar: { type: 'string', description: '日历名称', default: '工作', }, datePattern: { type: 'string', description: '目标日期模式,如:2025-07-10', }, corrections: { type: 'array', items: { type: 'object', properties: { keyword: { type: 'string', description: '事件关键词' }, newStartTime: { type: 'string', description: '新开始时间 HH:MM' }, newEndTime: { type: 'string', description: '新结束时间 HH:MM' } }, required: ['keyword', 'newStartTime', 'newEndTime'] }, description: '时间修正列表' } }, required: ['calendar', 'datePattern', 'corrections'], additionalProperties: false, },
- macos-calendar-mcp-sdk.js:191-223 (registration)Registration of the 'fix-event-times' tool in the ListToolsRequestSchema response, providing name, description, and inputSchema.{ name: 'fix-event-times', description: '修正错误的事件时间(从凌晨修正到正确时间)', inputSchema: { type: 'object', properties: { calendar: { type: 'string', description: '日历名称', default: '工作', }, datePattern: { type: 'string', description: '目标日期模式,如:2025-07-10', }, corrections: { type: 'array', items: { type: 'object', properties: { keyword: { type: 'string', description: '事件关键词' }, newStartTime: { type: 'string', description: '新开始时间 HH:MM' }, newEndTime: { type: 'string', description: '新结束时间 HH:MM' } }, required: ['keyword', 'newStartTime', 'newEndTime'] }, description: '时间修正列表' } }, required: ['calendar', 'datePattern', 'corrections'], additionalProperties: false, }, },
- macos-calendar-mcp-sdk.js:248-249 (registration)Dispatch/registration in the CallToolRequestSchema switch statement that routes calls to the fixEventTimes handler.case 'fix-event-times': return await this.fixEventTimes(args);
- macos-calendar-mcp-sdk.js:268-285 (helper)Helper function to parse date string into components for AppleScript date setting, used in fixEventTimes.formatDateForAppleScript(dateStr) { // 输入格式:YYYY-MM-DD HH:MM const [datePart, timePart] = dateStr.split(' '); const [year, month, day] = datePart.split('-').map(Number); const [hour, minute] = timePart.split(':').map(Number); if (!year || !month || !day || hour === undefined || minute === undefined) { throw new Error(`无效的日期格式: ${dateStr},请使用 YYYY-MM-DD HH:MM 格式`); } return { year, month, day, hour, minute }; }