Skip to content

Instantly share code, notes, and snippets.

@mr-eyes
Last active February 7, 2024 23:16
Show Gist options
  • Save mr-eyes/b6bb736b2f64a2c4ae3316ed6c52b834 to your computer and use it in GitHub Desktop.
Save mr-eyes/b6bb736b2f64a2c4ae3316ed6c52b834 to your computer and use it in GitHub Desktop.
Google Slides Agenda Tracking Bar Script
function addOrUpdateAgendaBarImproved() {
var presentation = SlidesApp.getActivePresentation();
var slides = presentation.getSlides();
var sections = [
{ name: 'Motivation', slides: [2, 3] },
{ name: 'Scientific Background', slides: [4, 5] },
{ name: 'Methods', slides: [6, 7] },
{ name: 'Use case 1', slides: [8, 11] },
{ name: 'Use Case 2', slides: [12, 15] },
{ name: 'Future Directions', slides: [16, 17] },
{ name: 'PhD Thesis', slides: [18, 50] },
];
// Adjustments for fitting the bar within the slide
var totalWidth = presentation.getPageWidth() - 10; // Use the full width of the slide
var barHeight = 20; // Height of the agenda bar
var posY = presentation.getPageHeight() - barHeight - 10; // Adjust Y position to fit at the bottom
var posXStart = 10; // Start from the very left of the slide
slides.forEach((slide, slideIndex) => {
var sectionWidth = totalWidth / sections.length; // Divide total width by the number of sections
sections.forEach((section, index) => {
// Positioning for each section
var posX = posXStart + (sectionWidth * index);
// Determine if the current slide is within the section's range for coloring
var isActiveSection = slideIndex + 1 >= section.slides[0] && slideIndex + 1 <= section.slides[1];
var fillColor = isActiveSection ? '#34A853' : '#dddddd'; // Active or inactive color
// Insert a rectangle for each section
var shape = slide.insertShape(SlidesApp.ShapeType.FOLDED_CORNER, posX, posY, sectionWidth, barHeight);
shape.getFill().setSolidFill(fillColor);
// Text setup
var textRange = shape.getText();
textRange.setText(section.name);
var textStyle = textRange.getTextStyle();
textStyle.setFontSize(8).setBold(true).setForegroundColor('#ffffff'); // Text styling
textRange.getParagraphStyle().setParagraphAlignment(SlidesApp.ParagraphAlignment.CENTER);
});
});
SlidesApp.getUi().alert('Agenda bar design updated on all slides.');
}
@mr-eyes
Copy link
Author

mr-eyes commented Feb 7, 2024

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment