Newbie scripter looking for help in triggering a script only on highlighted cells

36 views
Skip to first unread message

Anonanon Anonanon

unread,
Sep 22, 2022, 1:37:24 PM9/22/22
to Google Apps Script Community
Hello, all! First-timer here. This looks like a great community. 

I've written a script (with the help of an instructional video) to export events from a Sheet to Google Calendar. The hitch I've run into is that the sheet will be continually updated and syncing it to Calendar repeatedly will create a whole lot of duplicate events. 

My question is if the script I've written can be modified to only trigger on highlighted cells. Here is the script: 

function contentTracker() {
  var spreadsheet = SpreadsheetApp.getActiveSheet();
  var calendarId = spreadsheet.getRange("A1").getValue();
  var eventCal = CalendarApp.getCalendarById(calendarId);

  var content = spreadsheet.getRange("B3:D3").getValues();

for (x=0; x<content.length; x++) {

  var shift = content[x];

  var name = shift[0];
  var startTime = shift[1];
  var endTime = shift[2];

  eventCal.createEvent(name, startTime, endTime);

  }
}

Thanks in advance! 

Kevin -

unread,
Sep 25, 2022, 11:06:47 AM9/25/22
to Google Apps Script Community
What do you mean by "highlighted cells". There's no getBackground() statements in your code, so where's the highlighting?

Clark Lind

unread,
Sep 26, 2022, 7:49:16 AM9/26/22
to Google Apps Script Community
I think he means "selected" or "active" cell. 

Kevin -

unread,
Sep 26, 2022, 12:23:20 PM9/26/22
to Google Apps Script Community
I see. Well, it's still kinda vague. If the word "trigger" in AA's post is operative, then maybe the answer lies with the simple trigger: onSelectionChange()?

Anonanon Anonanon

unread,
Sep 26, 2022, 12:27:37 PM9/26/22
to Google Apps Script Community
Hello, and thank you for your response! 

I'm trying to modify the script I listed above so that it will trigger only on the group of cells that is selected at the time, thus avoiding the issue of having the calendar populated repeatedly by everything on the spreadsheet. There's nothing in the script because, sadly, I don't know where to start! 

Reply all
Reply to author
Forward
0 new messages