Newbie question: How to use my own WebApp/Add-on

53 views
Skip to first unread message

Martin Heitmann

unread,
Mar 5, 2023, 9:24:47 AM3/5/23
to Google Apps Script Community
Hello everyone

I have never used Google Apps Scripts before and now I wanted to have something like a macro for my Google Calendar (web browser version). My use case was that I wanted to click on a day and with the macro/webapp/addon (I don't know what is right) I wanted with a single click to add an event at a certain time and with a certain title (always the same time and the same title).

Therefore I turned to ChatGPT, which was quite entertaining. It led me to Google Docs and in a new document I entered via Extensions menu -> Apps Script. With the help of ChatGPT I got this

[code]
function createNewEvent() {
var calendarName = "Anni_und_Martin"; // Name des Kalenders, in den der Termin hinzugefügt werden soll
var eventName = "Martin holt ab"; // Name des neuen Termins
var durationMinutes = 60; // Dauer des neuen Termins in Minuten

// Array mit den ausgewählten Kalender-Objekten abrufen
var selection = CalendarApp.getSelection();

// Startdatum aus dem ersten ausgewählten Kalender-Objekt extrahieren
var selectedDate = selection[0].getStartTime();

// Startzeit auf 15:30 Uhr festlegen
var startDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate(), 15, 30);

// Enddatum berechnen
var endDate = new Date(startDate.getTime() + durationMinutes * 60000);

// Kalender-Objekt für den ausgewählten Kalender erstellen
var calendar = CalendarApp.getCalendarsByName(calendarName)[0];

// neuen Termin erstellen und Eigenschaften festlegen
var newEvent = calendar.createEvent(eventName, startDate, endDate);

// neuen Termin speichern
newEvent.save();
}

function onOpen() {
var ui = SpreadsheetApp.getUi();

// Add-On Menü erstellen
ui.createAddonMenu()
.addItem('Termin hinzufügen', 'createNewEvent')
.addToUi();
}
[/code]

And there I am stuck. I tried to deploy that and thought that I could then find it via the little plus symbol in the Google Calendar web version on the right side. But there is only the market place. Can you give me advice, what I am missing?

Best regards
Martin
Reply all
Reply to author
Forward
0 new messages