Skip to main content
Glama

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
NameRequiredDescriptionDefault
calendarYes日历名称工作
datePatternYes目标日期模式,如:2025-07-10
correctionsYes时间修正列表

Implementation Reference

  • 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')}`, }, ], }; }
  • 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, },
  • 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, }, },
  • Dispatch/registration in the CallToolRequestSchema switch statement that routes calls to the fixEventTimes handler.
    case 'fix-event-times': return await this.fixEventTimes(args);
  • 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 }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xybstone/macos-calendar-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server