I’ve been successfully pulling my calendar events across several calendars with an action (pasted below with calendar names for this posting) that has suddenly stopped working.
I’ve not made any changes to any of the calendars it is pulling from… Nor to the action.
This issue started a week to 10 days before Drafts 54 was released (was not able to post till now.)
Can anyone make suggestions on:
- How to troubleshoot - I would not even know where to begin
- Make suggestions as to why this stopped working?
Many thanks.
Script from the action:
// Calendar Events to Clipboard - Extract meetings for specified date
// Prompt for date input
let prompt = new Prompt();
prompt.title = "Enter Date for Calendar Events";
prompt.message = "Enter date in YYYYMMDD format (e.g., 20250822)";
prompt.addTextField("dateInput", "Date", "", { placeholder: "20250822" });
prompt.addButton("Get Events");
prompt.addButton("Cancel");
if (!prompt.show() || prompt.buttonPressed === "Cancel") {
context.cancel("Action cancelled");
}
let inputDate = prompt.fieldValues["dateInput"].trim();
// Validate date format (basic check for 8 digits)
if (!/^\d{8}$/.test(inputDate)) {
app.displayErrorMessage("Invalid date format. Please use YYYYMMDD (e.g., 20250822)");
context.cancel("Invalid date format");
}
// Get calendar events for the specified date
let targetDate = new Date(
parseInt(inputDate.substr(0, 4)), // year
parseInt(inputDate.substr(4, 2)) - 1, // month (0-based)
parseInt(inputDate.substr(6, 2)) // day
);
let calendarNames = ["EMO", "MOOFrasca", "Farm2", "jmf@123.com"];
let allEvents = [];
// Get events from each specified calendar
for (let calName of calendarNames) {
try {
let cal = Calendar.findOrCreate(calName);
if (cal) {
let startOfDay = new Date(targetDate);
startOfDay.setHours(0, 0, 0, 0);
let endOfDay = new Date(targetDate);
endOfDay.setHours(23, 59, 59, 999);
let events = cal.events(startOfDay, endOfDay);
allEvents = allEvents.concat(events);
}
} catch (error) {
console.log(`Could not access calendar: ${calName} - ${error.message}`);
}
}
// Process calendar events into clipboard format
let clipboardEntries = [];
for (let event of allEvents) {
if (!event.isAllDay) {
// Skip EFL Standup meetings (standing meeting)
if (event.title.toLowerCase().includes("efl standup")) {
continue;
}
let startTime = event.startDate;
let hour = String(startTime.getHours()).padStart(2, '0');
let minute = String(startTime.getMinutes()).padStart(2, '0');
let militaryTime = `${hour}:${minute}`;
clipboardEntries.push({
time: militaryTime,
timeInMinutes: startTime.getHours() * 60 + startTime.getMinutes(),
title: event.title,
line: `${militaryTime} ${event.title}`
});
}
}
// Sort entries by time
clipboardEntries.sort((a, b) => a.timeInMinutes - b.timeInMinutes);
// Create clipboard content
let clipboardContent = clipboardEntries.map(entry => entry.line).join('\n');
if (clipboardEntries.length > 0) {
// Copy to clipboard
app.setClipboard(clipboardContent);
// Display success message
app.displayInfoMessage(`${clipboardEntries.length} calendar event(s) copied to clipboard for ${inputDate}`);
// Log the entries
console.log(`Calendar events for ${inputDate} copied to clipboard:`);
clipboardEntries.forEach(entry => {
console.log(entry.line);
});
} else {
app.displayInfoMessage(`No calendar events found for ${inputDate}`);
console.log(`No calendar events found for date ${inputDate}`);
}
