fix-event-times
Adjust incorrect event times in macOS Calendar to accurate values, correcting misplaced events scheduled at midnight to their intended hours using configured keyword triggers and new time values.
Instructions
修正错误的事件时间(从凌晨修正到正确时间)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| calendar | Yes | 日历名称 | 工作 |
| corrections | Yes | 时间修正列表 | |
| datePattern | Yes | 目标日期模式,如:2025-07-10 |
Input Schema (JSON Schema)
{
"additionalProperties": false,
"properties": {
"calendar": {
"default": "工作",
"description": "日历名称",
"type": "string"
},
"corrections": {
"description": "时间修正列表",
"items": {
"properties": {
"keyword": {
"description": "事件关键词",
"type": "string"
},
"newEndTime": {
"description": "新结束时间 HH:MM",
"type": "string"
},
"newStartTime": {
"description": "新开始时间 HH:MM",
"type": "string"
}
},
"required": [
"keyword",
"newStartTime",
"newEndTime"
],
"type": "object"
},
"type": "array"
},
"datePattern": {
"description": "目标日期模式,如:2025-07-10",
"type": "string"
}
},
"required": [
"calendar",
"datePattern",
"corrections"
],
"type": "object"
}
Implementation Reference
- macos-calendar-mcp-sdk.js:612-674 (handler)The handler function for the 'fix-event-times' tool. It iterates over corrections, constructs new date times, generates AppleScript to update matching events' start and end dates in the specified calendar, executes it via osascript, and returns a summary of fixes.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, newStartTime, newEndTime.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)The tool registration in the ListTools response, including name, description, and inputSchema for 'fix-event-times'.{ 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)The switch case in CallToolRequestSchema handler that dispatches to the fixEventTimes method.case 'fix-event-times': return await this.fixEventTimes(args);