게시된 편집기 부가기능은 편집기의 확장 프로그램 메뉴 아래에 맞춤 메뉴 항목을 만들 수 있습니다. Ui.createAddonMenu() 메서드를 사용하여 부가기능 메뉴를 삽입하고 Menu.addItem() 메서드를 사용하여 항목을 추가할 수 있습니다. 메뉴는 일반적으로 부가기능의 onOpen(e) 메서드에서 생성됩니다.
사용자 상호작용 또는 부가기능 상태에 따라 변경되는 동적 메뉴를 만들 수 있습니다. 하지만 사용자가 애드온을 승인하기 전에 애드온이 초기 메뉴를 만들어야 합니다. 따라서 onOpen(e)에서 메뉴를 구성하기 전에 부가기능의 승인 모드를 확인해야 합니다. 부가기능이 ScriptApp.AuthMode.NONE 상태일 때는 승인이 필요한 작업 (예: 스크립트 Properties 확인)을 시도하지 마세요. 승인 모드 및 수명 주기에 관한 자세한 내용은 승인 수명 주기를 참고하세요.
다음 예는 다양한 승인 모드에 맞는 동적 부가기능 메뉴를 빌드하는 방법을 보여줍니다.
functiononOpen(e){varmenu=SpreadsheetApp.getUi().createAddonMenu();//OrDocumentApporSlidesApporFormApp.if(e && e.authMode==ScriptApp.AuthMode.NONE){//Addanormalmenuitem(worksinallauthorizationmodes).menu.addItem('Start workflow','startWorkflow');}else{//Addamenuitembasedonproperties(doesn't work in AuthMode.NONE).varproperties=PropertiesService.getDocumentProperties();varworkflowStarted=properties.getProperty('workflowStarted');if(workflowStarted){menu.addItem('Check workflow status','checkWorkflow');}else{menu.addItem('Start workflow','startWorkflow');}//Recordanalytics.UrlFetchApp.fetch('http://www.example.com/analytics?event=open');}menu.addToUi();}
[null,null,["최종 업데이트: 2025-07-31(UTC)"],[[["\u003cp\u003ePublished Editor Add-ons can create custom menu items under the Extensions menu using \u003ccode\u003eUi.createAddonMenu()\u003c/code\u003e and \u003ccode\u003eMenu.addItem()\u003c/code\u003e, typically within the add-on's \u003ccode\u003eonOpen(e)\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eWhile unpublished add-ons can create top-level menus, it's recommended to use \u003ccode\u003eUi.createAddonMenu()\u003c/code\u003e for published add-ons to ensure consistent user experience.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons must create an initial menu before user authorization and adjust menu items dynamically based on the authorization mode (\u003ccode\u003eScriptApp.AuthMode\u003c/code\u003e) to avoid errors.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example demonstrates building a dynamic add-on menu that adapts to different authorization modes, using \u003ccode\u003eScriptApp.AuthMode.NONE\u003c/code\u003e to control actions requiring authorization.\u003c/p\u003e\n"]]],["Editor add-ons create custom menu items under the **Extensions** menu using `Ui.createAddonMenu()` and `Menu.addItem()`, typically within the `onOpen(e)` method. Menus must be defined *before* user authorization, necessitating a check of the add-on's authorization mode. Dynamic menus can change based on user interactions. Actions requiring authorization should not be performed when `AuthMode.NONE`. The provided example shows a dynamic menu construction for different modes, adding either \"Start workflow\" or \"Check workflow status\".\n"],null,["# Custom menus for Editor add-ons\n\nPublished [Editor add-ons](/workspace/add-ons/concepts/types#editor_add-ons)\ncan create custom menu items under their editor's **Extensions** menu. You can\ninsert an add-on menu by using the\n[`Ui.createAddonMenu()`](/apps-script/reference/base/ui#createAddonMenu()) method\nand add items to it using the\n[`Menu.addItem()`](/apps-script/reference/base/menu#addItem(String,String))\nmethod. Menus are usually created in the add-on's `onOpen(e)` method.\n| **Caution:** Unpublished add-ons can also [create custom top-level menus](/apps-script/guides/menus#custom_menus_in_google_docs_sheets_slides_or_forms), but these are automatically moved under the **add-ons** menu if the add-on is published and may not result in the user experience you intended. If you intend to publish the add-on, always use [`Ui.createAddonMenu()`](/apps-script/reference/base/ui#createAddonMenu()) to define the add-on menu.\n\nYou can create dynamic menus that change based on user interactions or add-on\nstate. However, add-ons must create an initial menu *before* the add-on is\nauthorized by the user. Because of this, you must check the add-on's\n[authorization mode](/workspace/add-ons/concepts/editor-auth-lifecycle#authorization_modes)\nprior to constructing menus in `onOpen(e)`. Do not attempt to take any action\nthat requires authorization (such as checking the script\n[`Properties`](/apps-script/reference/properties))\nwhile the add-on is in `ScriptApp.AuthMode.NONE`. See the\n[authorization lifecycle](/workspace/add-ons/concepts/editor-auth-lifecycle#the_complete_lifecycle)\nfor more details on the authorization modes and lifecycle.\n| **Warning:** If you attempt to take actions that require authorization when the authorization mode is `ScriptApp.AuthMode.NONE`, it results in an error. This may prevent your add-on menus from being displayed.\n\nThe following example shows how to build a dynamic add-on menu for different\nauthorization modes: \n\n function onOpen(e) {\n var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp or SlidesApp or FormApp.\n if (e && e.authMode == ScriptApp.AuthMode.NONE) {\n // Add a normal menu item (works in all authorization modes).\n menu.addItem('Start workflow', 'startWorkflow');\n } else {\n // Add a menu item based on properties (doesn't work in AuthMode.NONE).\n var properties = PropertiesService.getDocumentProperties();\n var workflowStarted = properties.getProperty('workflowStarted');\n if (workflowStarted) {\n menu.addItem('Check workflow status', 'checkWorkflow');\n } else {\n menu.addItem('Start workflow', 'startWorkflow');\n }\n // Record analytics.\n UrlFetchApp.fetch('http://www.example.com/analytics?event=open');\n }\n menu.addToUi();\n }"]]