Created
March 11, 2014 23:00
-
-
Save rachelslurs/9496821 to your computer and use it in GitHub Desktop.
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
/** | |
* The onOpen function runs automatically when the Google Docs document is | |
* opened. Use it to add custom menus to Google Docs that allow the user to run | |
* custom scripts. For more information, please consult the following two | |
* resources. | |
* | |
* Extending Google Docs developer guide: | |
* https://developers.google.com/apps-script/guides/docs | |
* | |
* Document service reference documentation: | |
* https://developers.google.com/apps-script/reference/document/ | |
*/ | |
function onOpen() { | |
DocumentApp.getUi().createMenu('Template Tags') | |
.addItem('Replace Me!', 'replaceMe') | |
.addToUi(); | |
} | |
function replaceMe () { | |
var result = DocumentApp.getUi().prompt('What do you want to change {{REPLACE_ME}} to?', DocumentApp.getUi().ButtonSet.OK_CANCEL); | |
var responseText = null; | |
if(result.getSelectedButton() == DocumentApp.getUi().Button.OK){ | |
responseText = result.getResponseText(); | |
if (responseText.length > 0) { | |
var bodyElement = DocumentApp.getActiveDocument().getBody(); | |
bodyElement.replaceText('{{REPLACE_ME}}', responseText); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment