Skip to content

[BUG] Apple Calendar add tool creates events only for the current day, ignoring specified date #19

@ianliuy

Description

@ianliuy

Who is affected?
Users of applescript-mcp's calendar_add tool who attempt to schedule events for any date other than the current system date.

What is the bug?
The calendar_add tool fails to correctly set the date for new calendar events. It always creates events for the current system date, even if the startDate and endDate arguments specify a different date. While the time (hours, minutes, seconds) is correctly applied, the year, month, and day from the input are ignored.

When does this bug occur?
This bug occurs whenever a user attempts to add a calendar event for any date other than "today" using the calendar_add tool.

  • Example: If today is May 28, 2025, and a user attempts to add an event for May 29, 2025, using the following:
    <use_mcp_tool>
    <server_name>applescript-mcp</server_name>
    <tool_name>calendar_add</tool_name>
    <arguments>
    {
      "title": "abcxyz",
      "startDate": "2025-05-29 09:30:00",
      "endDate": "2025-05-29 10:30:00"
    }
    </arguments>
    </use_mcp_tool>
    The event will be incorrectly created on May 28, 2025, at 09:30:00, instead of May 29, 2025.

Where is the code causing this bug?
The problematic logic resides in the AppleScript generation part of the calendar_add function in src/categories/calendar.ts, specifically around line 41.

Why does this bug occur?
The AppleScript initializes theStartDate (and subsequently theEndDate) using current date. It then only updates the hours, minutes, and seconds of this date object by slicing the relevant parts from args.startDate.

The specific code snippet responsible:

          set theStartDate to current date
          set hours of theStartDate to ${args.startDate.slice(11, 13)}
          set minutes of theStartDate to ${args.startDate.slice(14, 16)}
          set seconds of theStartDate to ${args.startDate.slice(17, 19)}

This code does not parse or set the year, month, and day components from the args.startDate string, causing them to default to the components of the current date. The same issue applies to theEndDate and args.endDate.

How can this bug be fixed?
The fix involves modifying the AppleScript generation to explicitly parse and set the year, month, and day from args.startDate (and args.endDate) for theStartDate (and theEndDate) respectively.

These lines should be added before the existing time component assignments for theStartDate:

          set year of theStartDate to ${args.startDate.slice(0, 4)}
          set month of theStartDate to ${args.startDate.slice(5, 7)}
          set day of theStartDate to ${args.startDate.slice(8, 10)}

So the corrected block for theStartDate would look like:

          set theStartDate to current date // Or initialize differently if more robust
          set year of theStartDate to ${args.startDate.slice(0, 4)}
          set month of theStartDate to ${args.startDate.slice(5, 7)} // Note: AppleScript month is 1-12
          set day of theStartDate to ${args.startDate.slice(8, 10)}
          set hours of theStartDate to ${args.startDate.slice(11, 13)}
          set minutes of theStartDate to ${args.startDate.slice(14, 16)}
          set seconds of theStartDate to ${args.startDate.slice(17, 19)}

A similar modification needs to be applied for theEndDate using args.endDate to ensure the end date is also correctly set.

Proposed complete corrected section for theStartDate and theEndDate:

          // For startDate
          set theStartDate to current date // Essential to have a date object to modify
          set year of theStartDate to ${args.startDate.slice(0, 4)}
          set month of theStartDate to ${args.startDate.slice(5, 7)}
          set day of theStartDate to ${args.startDate.slice(8, 10)}
          set hours of theStartDate to ${args.startDate.slice(11, 13)}
          set minutes of theStartDate to ${args.startDate.slice(14, 16)}
          set seconds of theStartDate to ${args.startDate.slice(17, 19)}

          // For endDate
          set theEndDate to current date // Essential to have a date object to modify
          set year of theEndDate to ${args.endDate.slice(0, 4)}
          set month of theEndDate to ${args.endDate.slice(5, 7)}
          set day of theEndDate to ${args.endDate.slice(8, 10)}
          set hours of theEndDate to ${args.endDate.slice(11, 13)}
          set minutes of theEndDate to ${args.endDate.slice(14, 16)}
          set seconds of theEndDate to ${args.endDate.slice(17, 19)}

This will ensure the full date and time from the input arguments are respected.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions