Need help deleting an event from a calendar


#1

Hi!, I’m new here and at the moment I’m trying to learn JavaScript, but I have a problem that I don’t know how to fix right now.

I’ve downloaded a couple scripts that allow you to see events for today and this week, but every time I run then I have an event in them that shows up that I can’t find in any of my calendars.

I was trying to figure out how to make a script like the example script that removes a notification, except it removes a calendar event. Unfortunately I don’t know much about JavaScript right now, so I can’t really figure out how to do it. If someone on here could help me out with a script that could potentially delete this event that would be great!

For a little more information, I’ll add the scripts that show the weekly, and daily events so that you might be able to modify them.

Thanks so much if you could help me out!!

function handleEvents(events) {    
let uiTable = new UITable();
let i;
for (i = 0; i < events.length; i++) {
    let uiTableRow = new UITableRow();
    let event = events[i];
    if (event.isAllDay) continue;
    let titleCell = uiTableRow.addText(event.title);
    uiTableRow.addText(formatTime(event.startDate));
    uiTableRow.addText(formatTime(event.endDate));
    uiTableRow.height = 40;
    uiTableRow.cellSpacing = 10;
    uiTable.addRow(uiTableRow);
}
QuickLook.present(uiTable);}
function handleErr(val) {
console.error(val);
}

function handleCalendars(calendars) {
let i;
for (i = 0; i < calendars.length; i++) {
    let calendar = calendars[i];
    console.log ('Calendar: ' + calendar.title);
}
CalendarEvent.thisWeek().then(handleEvents, handleErr);
}

function formatTime(date) {
return date.toLocaleTimeString("en-US", {hour: "2-digit", minute: "2-digit"});
}

CalendarEvent.today().then(handleCalendars, handleErr);

#2

Can you determine what the date, time and Calendar it belongs to are?

Rather than just deleting it you might want to check the details for it? Perhaps you are looking at events in your calendar(s) that only have specific times and it is an all day event. Perhaps you have a non-displayed calendar (e.g. Birthdays) that it is being read from?


#3

I’m not sure how to determine the date or calendar that it’s in. When I search my calendars (all that are on my phone) it doesn’t show up as anything. I’m only able to see it when running the scriptable script. And when I use the script that shows the daily calendar, it brings it up every day, so somehow I think this ghost of an event is still lingering around.

The script I added when I was looking at it doesn’t open a specific calendar, so I figure it must be just floating around somewhere.


#4

Calendars are associated with the events, so it won’t be floating around without one. I’ve put together the script below for you. It should help you identify some specific details about your “ghost” event.

When you run it, you should get a screen showing you four options.

  1. Last week
  2. This week
  3. Next week
  4. This month

Hopefully one or two of those will help you track down your event. If it doesn’t cover the required period, hopefully it is straight forward enough for you to modify for a suitable date range (take a look at option 4 :wink: ).

When you tap on one of those it will write the list out to Scriptable’s console, noting the title of the calendar the event belongs to, the title of the event, if the event is all day and the date/times that go along with that type of event.

Here’s the script. Hope it helps.

//Build a menu and launch the event processing function with the range of events for the specified period.
let tblMenu = new UITable();
const intHeight = 30;

//Header
let rowHead = new UITableRow();
rowHead.isHeader = true;
rowHead.addText("Choose Period", "Tap on the period you would like to list events for.  The results will be shown in the console.");
tblMenu.addRow(rowHead);

//Option 1 - last week
let rowData1 = new UITableRow();
rowData1.height = intHeight;
let btnData1 = rowData1.addButton("> Last Week", "");
btnData1.dismissOnTap = true;
btnData1.onTap = () => 
{
	console.log("<< LAST WEEK >>");
	CalendarEvent.lastWeek().then(procEvents, doErr);
}
tblMenu.addRow(rowData1);

//Option 2 - this week
let rowData2 = new UITableRow();
rowData2.height = intHeight;
let btnData2 = rowData2.addButton("> This Week", "");
btnData2.dismissOnTap = true;
btnData2.onTap = () => 
{
	console.log("<< THIS WEEK >>");
	CalendarEvent.thisWeek().then(procEvents, doErr);
}
tblMenu.addRow(rowData2);

//Option 3 - next week
let rowData3 = new UITableRow();
rowData3.height = intHeight;
let btnData3 = rowData3.addButton("> Next Week", "");
btnData3.dismissOnTap = true;
btnData3.onTap = () => 
{
	console.log("<< NEXT WEEK >>");
	CalendarEvent.nextWeek().then(procEvents, doErr);
}
tblMenu.addRow(rowData3);

//Option 4 - this month
let rowData4 = new UITableRow();
rowData4.height = intHeight;
let btnData4 = rowData4.addButton("> This Month", "");
btnData4.dismissOnTap = true;
btnData4.onTap = () => 
{
	console.log("<< THIS MONTH >>");

	let dtTemp = new Date(), intYear = dtTemp.getFullYear(), intMonth = dtTemp.getMonth();
	let dtFrom = new Date(intYear, intMonth, 1, 0, 0, 0);
	let dtTo = new Date(intYear, intMonth + 1, 0, 0,0,0);

	CalendarEvent.between(dtFrom, dtTo).then(procEvents, doErr);
}
tblMenu.addRow(rowData4);

//Display the menu
await tblMenu.present();


//Process the events
function procEvents(events)
{
	const tzUTC = { timeZone: "UTC" };
	
	//Blank line
	console.log("");
	
	//write out a header
	console.log("------------------------------------------------");
	console.log("CALENDAR : EVENT : PERIOD");
	console.log("------------------------------------------------");
	
	//Loop through and output the details for each event
	let intCount = 0;
	for (intCount = 0; intCount < events.length; intCount++)
	{
		let event = events[intCount];
		let strEvt = event.calendar.title;
		strEvt += " : " + event.title;
		if (event.isAllDay)
		{
			strEvt += " : All Day";
			strEvt += " (" + event.startDate.toLocaleString("en-GB", tzUTC) + ")";
		}
		else
		{
			strEvt += " : In Day";
			strEvt += " (" + event.startDate.toLocaleString("en-GB", tzUTC);
			strEvt += " - " + event.endDate.toLocaleString("en-GB", tzUTC) + ")";
		}
		console.log(strEvt);
	}
	console.log("------------------------------------------------");
}

//Dump out any error information
function doErr(val)
{
	console.log("ERROR");
	console.error(val);
}

#5

Well it definitely helped me find where it is! It showed up in a calendar called “Found in Natural Language” which is definitely not a calendar that I have.

I guess the only problem now is being able to find that calendar. Thanks so much for writing that!


#6

So I found the solution now. I looked around some Apple forums that said people had found the iCloud calendar for found in natural language.

I went to settings and found in the calendar tab and in Siri and search there is a tick that says “Find events in other apps” that I turned off. When I ran the script again, the option was gone. I have no idea where this event came from, because it was an event on Christmas Eve, but :man_shrugging:t3: Thank you so much again!