Welcome to your first foray into Google Apps Script! Just like in many programming introductions, we'll start with the classic 'Hello, World!' program. This simple script will help you understand how to write, save, and run code within the Google Apps Script editor, setting a foundation for more complex automations.
To begin, you need to access the Google Apps Script editor. You can do this from any Google Workspace application like Sheets, Docs, Forms, or Slides. For this example, let's use Google Sheets. Open a new or existing Google Sheet, then navigate to 'Extensions' > 'Apps Script'. This will open the script editor in a new browser tab.
You'll see a default function named myFunction. We'll replace its contents with our 'Hello, World!' code. The Logger.log() function is a powerful tool for debugging. It prints messages to the execution log, which is incredibly useful for understanding what your script is doing.
function myFunction() {
Logger.log('Hello, World!');
}Now, let's save your script. Click the floppy disk icon (Save project) in the toolbar. You'll be prompted to give your script a project name. Something descriptive like 'My First Script' or 'Hello World Script' is perfect. Click 'Rename'.
To run your script, ensure the myFunction is selected in the dropdown menu next to the 'Debug' button. Then, click the 'Run' button (the play icon). You might be asked to authorize the script. This is normal, as Apps Script needs permission to interact with your Google services. Review the permissions and click 'Allow'.
After the script runs, you won't see any visible change in your Google Sheet. To check the output of Logger.log(), you need to view the execution log. Go to 'View' > 'Executions' in the script editor. You should see a recent execution. Click on it, and you'll find 'Hello, World!' displayed in the 'Logs' section.
graph TD; A[Open Google Sheet] --> B(Extensions > Apps Script); B --> C{Script Editor Opens}; C --> D[Replace default function]; D --> E[Add Logger.log('Hello, World!')]; E --> F[Save Project]; F --> G[Run Script]; G --> H{Authorization Required?}; H -- Yes --> I[Allow Script]; H -- No --> J[View > Executions]; I --> J; J --> K[Check Logs for Output];