קל לארגן דפים בעזרת אוספים אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
טריגרים של Apps Script גורמים להרצה של פונקציית סקריפט ספציפית (פונקציית הטריגר) בכל פעם שמתרחש אירוע ספציפי. רק אירועים מסוימים יכולים להפעיל טריגרים, וכל אפליקציית Google Workspace תומכת בקבוצה שונה של אירועים.
כשמופעל טריגר, נוצר אובייקט אירוע. מבנה ה-JSON הזה מכיל פרטים על האירוע שהתרחש. המידע במבנה של אובייקט האירוע מאורגן בצורה שונה בהתאם לסוג הטריגר.
אחרי שיוצרים את אובייקט האירוע, Apps Script מעביר אותו כפרמטר לפונקציית הגורם המפעיל. פונקציית הטריגר היא פונקציית קריאה חוזרת שאתם צריכים להטמיע בעצמכם, כדי לבצע את הפעולות המתאימות בתגובה לאירוע. לדוגמה, בתוסף ל-Google Workspace שמרחיב את Gmail, אפשר להגדיר טריגר שיוצר ממשק כרטיס חדש כשהמשתמש פותח שרשור הודעות. במקרה כזה, מטמיעים פונקציית קריאה חוזרת תלוית-הקשר כדי ליצור את הכרטיסים שמרכיבים את ממשק המשתמש החדש באמצעות הנתונים שמועברים באובייקט האירוע.
בדף הזה מפורטות הנחיות לשימוש בטריגרים בפרויקטים של תוספים ל-Google Workspace.
טריגרים של מניפסט
בניגוד לתוספים של Editor, תוספים ל-Google Workspace לא יכולים להשתמש כרגע בטריגרים פשוטים של Apps Script. במקום זאת, הם משתמשים בטריגרים שנועדו במיוחד לתוספים ל-Google Workspace: טריגרים של קובץ המניפסט.
טריגרים של מניפסט מוגדרים באופן מלא במניפסט של תוסף Google Workspace. דוגמאות לטריגרים של מניפסט:
טריגרים של דף הבית שיוצרים ומציגים את דף הבית של התוסף.
טריגרים של פתיחת אירוע ביומן שמציגים כרטיס חדש או מבצעים פעולות אחרות כשפותחים אירוע ביומן.
טריגרים של עדכון אירוע ביומן שמציגים כרטיס חדש או מבצעים פעולות אחרות כשמשתמש עורך אירוע ביומן ושומר אותו.
טריגרים של Drive onItemsSelected שמציגים כרטיס חדש או מבצעים פעולות אחרות כשמשתמש בוחר קובץ אחד או יותר או תיקיות ב-Drive.
טריגרים של כתיבת אימייל ב-Gmail שמציגים כרטיס של תוסף כשהמשתמש פותח את התוסף בחלון של כתיבת אימייל ב-Gmail.
טריגרים הקשריים של Gmail שמציגים כרטיס חדש או מבצעים פעולות אחרות כשהמשתמש פותח הודעה ב-Gmail.
Editor onFileScopeGranted triggers that display a new card when users grant authorization for the drive.file OAuth scope in the current Editor document.
ברשימה שלמעלה, רק הטריגרים של דף הבית הם לא קונטקסטואליים. כל השאר הם טריגרים קונטקסטואליים. מידע נוסף על הגדרות טריגר במניפסט זמין במאמר בנושא מניפסט.
בנוסף לגורמים מפעילים של מניפסט, תוספים של Google Workspace יכולים להשתמש גם בגורמים מפעילים שניתנים להתקנה של Apps Script.
הגבלות
יש הגבלות מסוימות על השימוש בטריגרים של מניפסט.
הטריגרים האלה משמשים רק בפרויקטים של תוספים ל-Google Workspace, ואין להם שימוש באפליקציות אחרות.
הטריגרים האלה מוגדרים במניפסט של התוסף ולא בקוד שלו, ולכן אי אפשר להשתמש בשירות Script של Apps Script כדי ליצור או לשנות אותם.
כרגע, טריגרים הקשריים ב-Gmail יכולים לכלול רק קריטריון unconditional. כלומר, טריגרים לפי הקשר מופעלים לכל הודעת אימייל, ללא קשר לתוכן.
לכל תוסף יכול להיות רק טריגר אחד מכל סוג, לכל משתמש ולכל מסמך.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-31 (שעון UTC)."],[[["\u003cp\u003eApps Script triggers execute a specific function when a defined event occurs within a Google Workspace application.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Workspace add-ons utilize manifest triggers, defined in the add-on's manifest, to respond to events like opening a document or composing an email.\u003c/p\u003e\n"],["\u003cp\u003eManifest triggers can be contextual, reacting to specific user actions within a document or application, or non-contextual, like those that build the add-on's homepage.\u003c/p\u003e\n"],["\u003cp\u003eWhile manifest triggers offer event-driven functionality, they have limitations, including restrictions on their use and creation methods.\u003c/p\u003e\n"]]],["Apps Script triggers initiate a script function when specific events occur, creating an event object with event details. This object is then passed to a user-implemented trigger function, enabling actions based on the event. Google Workspace add-ons use manifest triggers, defined in the add-on's manifest, to trigger actions like displaying cards on homepage, when opening/updating Calendar events, selecting Drive items, or opening a message in Gmail. Contextual triggers and installable triggers are also supported but with some restrictions.\n"],null,["# Triggers for Google Workspace add-ons\n\n[Apps Script triggers](/apps-script/guides/triggers) cause a specified script\nfunction (the *trigger function*) to execute whenever a specified event\noccurs. Only certain events can cause triggers to fire, and each\nGoogle Workspace application supports a different set of events.\n\nWhen a trigger fires, an *event object* is created. This JSON structure\ncontains details about the event that occurred. The information in the event\nobject structure is organized differently based on the trigger type.\n\nOnce the event object is created, Apps Script passes it as a parameter to the\ntrigger function. The trigger function is a callback function that you must\nimplement yourself, to take whatever actions are appropriate to respond to the\nevent. For example, in a\nGoogle Workspace add-on that extends Gmail, you can\ndefine a trigger that creates a new card interface when the user opens a message\nthread. In this case, you implement a contextual callback function to create\nthe cards making up the new UI using the data passed in the\n[event object](/workspace/add-ons/concepts/event-objects).\n\nThis page provides guidelines on using triggers in\nGoogle Workspace\nadd-on projects.\n\nManifest triggers\n-----------------\n\nUnlike Editor add-ons, Google Workspace add-ons\ncurrently can't use Apps Script [simple triggers](/apps-script/guides/triggers)\nInstead, they use triggers designed specifically for\nGoogle Workspace add-ons: *manifest triggers*.\n\nManifest triggers are defined completely in the\nGoogle Workspace add-on's\n[manifest](/workspace/add-ons/concepts/workspace-manifests). Examples of manifest triggers include the\nfollowing:\n\n- **Homepage triggers** that build and display the add-on homepage.\n- **Calendar eventOpen triggers** that display a new card or take other actions when a Calendar event is opened.\n- **Calendar eventUpdate triggers** that display a new card or take other actions when a user edits and saves a Calendar event.\n- **Drive onItemsSelected triggers** that display a new card or take other actions when a user selects one or more files or folders in Drive.\n- **Gmail compose triggers** that display an add-on card when the user opens the add-on in the Gmail compose window.\n- **Gmail contextual triggers** that display a new card or take other actions when the user opens a Gmail message.\n- **Editor onFileScopeGranted triggers** that display a new card when users grant authorization for the `drive.file` OAuth scope in the current Editor document.\n\nIn the above list, only homepage triggers are non-contextual; the rest are\ncontextual triggers. See [Manifest](/workspace/add-ons/concepts/workspace-manifests)\nfor more information about manifest trigger definitions.\n\nIn addition to manifest triggers, Google Workspace\nadd-ons can also use Apps Script\n[installable triggers](/apps-script/guides/triggers/installable).\n\n### Restrictions\n\nManifest triggers have certain restrictions to their use.\n\n- These triggers are only used in Google Workspace add-on projects; they have no purpose in any other application.\n- Since they are defined in the add-on manifest and not in its code, you can't use the Apps Script [`Script`](/apps-script/reference/script) service to create or modify these triggers.\n- Gmail contextual triggers currently can only have an `unconditional` criteria. This means contextual triggers fire for every email message, regardless of content.\n- Each add-on can only have one trigger of each type, per user, per document."]]