Chapter 4: Creating your first GAS project

* If you need help with the content of this article for work or development, individual support is available.

What you will be able to do in this chapter:

  • Create a new project with clasp create
  • Know the difference between "Standalone" and "Sheets"
  • Open project in VS Code
  • Time required: 10-15 minutes
  • Stumbling block: code . doesn't work (Opening manually is OK!)

We will create the first automation project. This is like a "work room" prepared for each of your business issues, such as "Invoice Auto-creation Robot" or "Sales Report Aggregation Robot". We will carefully explain how to create a room with the clasp create command and check the contents.

1. Create a "Work Room" for the project

First, prepare a "work room (folder)" dedicated to the automation program you are about to create in your computer. In the world of programming, "Prepare one dedicated room (folder) for one job (project)" is the basic rule. By separating rooms, you prevent accidents where invoice creation code and customer management code get mixed up.

In the terminal (black screen), let's type the following spells line by line.

# First move to Desktop
cd Desktop

# Create a new folder (Name is free, but let's make it "my-first-robot" this time)
mkdir my-first-robot

# Enter the created folder
cd my-first-robot

Now you have moved to an empty work room named my-first-robot. This is the development base for the robot that will be your first subordinate.

2. Create a new GAS project

In this empty room, ask your subordinate to "Prepare for a new job".

clasp create --title "Invoice Creation Robot"
  • create: Create a new job
  • --title "...": This is the name of the job

By the way, you can also create it in one shot by skipping questions by adding options like clasp create --type sheets --title "...".

Then, the subordinate asks "What kind of job is it?" (Select with arrow keys and decide with Enter).

? What script do you want to create? (Use arrow keys)
> standalone
  docs
  sheets
  slides
  forms
  webapp
  api

This time, select the top standalone and press Enter.

Which one should I choose? (Standalone vs Others)

  • standalone (Independent type): Independent robot not tied to a specific file.
    • Example: Notify weather to Slack every morning at 9, organize files in Drive.
  • sheets / docs / forms (Attached type): Robot "parasitic" to a specific spreadsheet or document.
    • Example: Add a menu when this spreadsheet is opened, run the moment a form is submitted.

This time, we will proceed with standalone which is the simplest and easiest to manage. This means "an independent robot that does not depend on a specific Excel file (spreadsheet)". For example, work like "Create 50 invoice PDFs for last month on the 1st of every month and save them to Google Drive" is suitable for this standalone.

If Created new standalone script: ... is displayed, it is successful! Now, a new work space named "Invoice Creation Robot" has been secured on Google's server.

Let's try typing the following command.

clasp open

The browser should start up and the Google Apps Script editor screen should open. This is the "work room on the cloud" you just created.

3. Check what happened

If successful, two files are automatically generated in the "work room (folder)" of your computer. Let's check the contents by typing ls (for Mac) or dir (for Windows) in the terminal.

Identity of generated files

  1. .clasp.json:
    • "Contact Information".
    • Important information "The my-first-robot folder on this computer is connected to the 'Invoice Creation Robot' project with ID: xxxxx on Google" is written.
    • Never delete or edit it. If this is gone, you will lose the means of contact with your subordinate.
  2. appsscript.json:
    • "Robot Specification".
    • Basic specifications of the robot such as "This robot works in Japan time (time zone setting)" or "This robot needs permission to send Gmail" are written.
    • You don't need to worry about the contents now. Just "Hmm, setting file" is OK.

4. Open "Blueprint" in VS Code

Here, we finally use a programmer-like command. Type the following in the terminal.

code .
  • code: Launch VS Code (Design Tool)
  • .: Open "Blueprint in this place (current folder)"

When you execute this, VS Code starts up, and the contents of the my-first-robot folder earlier should be displayed on the left side. This will be the workplace where you write the robot's brain (code).

5. Frequently Asked Questions (Q&A)

Q1. When do I use other than standalone?

A. Use when you want to link with a specific file. For example, if you want to create a menu that works only when this spreadsheet is opened, choose sheets. However, standalone which is easy to manage is recommended at first.

Q2. Can I change the folder name (my-first-robot) later?

A. Yes, it's okay. Even if you change the folder name, as long as the .clasp.json inside is safe, the connection with Google will not be cut.

Q3. VS Code does not open even if I type code .!

A. If the command is not found, let's open it manually. The code command may not be installed, but there is no need to panic.

  1. Start VS Code normally.
  2. Click "File" -> "Open Folder" in the menu.
  3. Select and open the my-first-robot folder created earlier.

This alone results in exactly the same state.

6. Understanding Check Quiz

Q1. What is the command to create a new project? A. clasp new B. clasp create C. clasp make

Q2. Which script type is recommended to choose first? A. sheets (Spreadsheet) B. docs (Document) C. standalone (Independent type)

Q3. How should I treat the automatically generated .clasp.json? A. Delete it because it's in the way B. Rewrite the contents and play C. Never touch it because it contains connection information with Google

Answer Check (Click to open)

Q1: B It is create.

Q2: C First, standalone which does not depend on anything is simple and easy to handle.

Q3: C If this is gone, you will not be able to communicate with the project on Google.


Thank you for your hard work! Now your computer and Google's server are connected, and a base for robot development is also ready. In the next chapter, we will finally use this VS Code to write the first order (code) to the robot. Let's learn how to give specific instructions such as "Create an invoice for Mr. A".


What to do in the next chapter:

  • Write GAS code in VS Code
  • Upload to cloud with clasp push
  • Actually run and check logs

>> Next Chapter: Chapter 5 Writing GAS code

Series Index

ZIDOOKA!

Need help with the content of this article?

I provide individual technical support related to the issues described in this article, as a freelance developer. If the problem is blocking your work or internal tasks, feel free to reach out.

Support starts from $30 USD (Estimate provided in advance)
Thank you for reading

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Policy on AI Usage

Some articles on this site are written with the assistance of AI. However, we do not rely entirely on AI for writing; it is used strictly as a support tool.