This repository contains a collection of Google Apps Scripts designed to automate and enhance various functionalities within Google Workspace. The scripts provide custom solutions for tasks in Google Sheets, Docs, Slides, and more, aiming to increase productivity and streamline workflows.
To use these scripts, follow these general steps:
- Open the Google Workspace product (e.g., Google Sheets) where you want to use the script.
- Click on "Extensions" -> "Apps Script".
- In the Apps Script editor, delete any existing code and replace it with the script you want to use.
- Click on the disk icon or select "File" -> "Save" to save your script.
- Close the Apps Script Editor and refresh your Google Workspace product page. You should now see the "Automation Tools" menu in the toolbar.
This script adds a function to the "Automation Tools" menu in Google Sheets. The function "Lock this file" locks the current file, making it read-only.
To use this script, follow the general instructions above. Then:
- Click on "Services" -> "+ Add a service", then add "Drive API".
- Click on "Deploy" -> "New deployment", then select "Web app" and deploy the script. You may need to give permissions to the script to access your Google Drive.
After refreshing your Google Sheets page, you should see the "Automation Tools" menu. Click on it and select "Lock this file" to lock the current file.
The script can be found in the repository under the filename lock_file_script.js
.
Here's the script:
function onOpen() {
var ui = SpreadsheetApp.getUi();
var menu = ui.getMenu('Automation Tools');
if (!menu) {
ui.createMenu('Automation Tools')
.addItem('Lock this file', 'lockFile')
.addToUi();
} else {
menu.addItem('Lock this file', 'lockFile');
}
}
function lockFile() {
var fileId = SpreadsheetApp.getActiveSpreadsheet().getId();
var update = {
contentRestrictions: [
{
readOnly: true,
reason: 'Finalized contract.'
}
]
};
Drive.Files.update(update, fileId);
}
Contributions are welcome! If you have a script you'd like to add or an improvement to an existing script, feel free to create a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.