Created
October 8, 2018 15:08
-
-
Save misterhay/c71e30ce2ba77217e68da91f57ec40aa to your computer and use it in GitHub Desktop.
Video Announcements Teleprompter Formatting Script (Google Apps Script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remember to add an on-open trigger for addMenu | |
function addMenu() { | |
var ui = DocumentApp.getUi(); | |
ui.createMenu('WBO Announcements') | |
.addItem('Format Announcements', 'formatAnnouncements') | |
.addToUi(); | |
} | |
function formatAnnouncements() { | |
var doc = DocumentApp.getActiveDocument(); | |
var body = doc.getBody(); | |
var paragraphs = body.getParagraphs(); | |
var numberOfParagraphs = paragraphs.length; | |
var styleNumber = 1; | |
for (var i=0; i<numberOfParagraphs; i++){ | |
var paragraph = paragraphs[i]; | |
paragraphText = paragraph.getText(); | |
var styleBlank = {}; | |
styleBlank[DocumentApp.Attribute.FONT_SIZE] = 10; | |
if (paragraphText == "") { // if paragraph is blank, set font size smaller | |
paragraph.setAttributes(styleBlank); | |
} | |
var styleDirections = {}; | |
styleDirections[DocumentApp.Attribute.FONT_SIZE] = 18; | |
styleDirections[DocumentApp.Attribute.ITALIC] = true; | |
styleDirections[DocumentApp.Attribute.FOREGROUND_COLOR] = '#00FF00'; | |
if (paragraphText.charAt(0) == "(") { // if it is stage directions, set to italics | |
paragraph.setAttributes(styleDirections); | |
} | |
// set colors | |
var style1 = {}; | |
style1[DocumentApp.Attribute.FONT_SIZE] = 17; | |
style1[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000'; | |
var style2 = {}; | |
style2[DocumentApp.Attribute.FONT_SIZE] = 17; | |
style2[DocumentApp.Attribute.FOREGROUND_COLOR] = '#0000FF'; | |
if (paragraphText == "" || paragraphText.charAt(0) == "(") { // skip if paragraph is blank or starts with a ( | |
} else { | |
if (styleNumber == 1) { | |
paragraph.setAttributes(style1); | |
styleNumber = 2; | |
} else { | |
paragraph.setAttributes(style2); | |
styleNumber = 1; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment