# Scripting help: Add separator in menu

**URL:** <https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142>\
**Category:** Scripting\
**Created:** [May 26, 2023, 4:45pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142 "2023-05-26T16:45:25Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![SCarewe](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/scarewe/32/18952_2.png) [@SCarewe](https://forum.glyphsapp.com/u/SCarewe)\
**Post date:** [May 26, 2023, 4:45pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/1 "2023-05-26T16:45:25Z")

</div>

Hello, I’m afraid I am having trouble figuring out how to correctly add a menu item separator in a plugin:  
 ![image](https://forum.glyphsapp.com/uploads/default/original/3X/7/6/764e462ea627a14c0800a7127cf8d0e420230421.png)  
How do I do this correctly? Using `"name": "-"` like in Vanilla doesn’t work, neither does an empty string (as you can see).

Is there any reference I can check for writing different menu items? Especially a fling-out menu would be a great help. Thanks!

For context, I have the following:

```auto
def conditionalContextMenus(self):

	if self.condition_met:
		
		conditionalMenus = [
			{"name": Glyphs.localize({"en": u"Show affected glyphs"}),
			 "action": self.openTabWithAffectedGlyphs_},
			# add a divider
			{"name": "", "disabled": True, "action": None}
			# add a submenu (fling-out)??
		]
		# Return list of context menu items
		return conditionalMenus

```

---

<div class="post-metadata">

**Author:** ![FlorianPircher](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/florianpircher/32/30457_2.png) [@FlorianPircher](https://forum.glyphsapp.com/u/FlorianPircher)\
**Post date:** [May 26, 2023, 4:56pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/2 "2023-05-26T16:56:53Z")

</div>

Try adding an item like so:

```python
{ "menu": NSMenuItem.separatorItem() }

```

---

<div class="post-metadata">

**Author:** ![SCarewe](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/scarewe/32/18952_2.png) [@SCarewe](https://forum.glyphsapp.com/u/SCarewe)\
**Post date:** [May 26, 2023, 5:42pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/3 "2023-05-26T17:42:17Z")

</div>

Thank you! That works perfectly. Do you have any guidance on how to add a submenu?

---

<div class="post-metadata">

**Author:** ![FlorianPircher](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/florianpircher/32/30457_2.png) [@FlorianPircher](https://forum.glyphsapp.com/u/FlorianPircher)\
**Post date:** [May 26, 2023, 5:52pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/4 "2023-05-26T17:52:14Z")

</div>

Same thing, but the `NSMenuItem` gets a submenu. See

> **[submenu | Apple Developer Documentation](https://developer.apple.com/documentation/appkit/nsmenuitem/1514845-submenu?language=objc)**
>
> The submenu of the menu item.

Something like:

```python
submenu = NSMenu.new()
# fill submenu
item = NSMenuItem.new()
item.setTitle_("Some Title")
item.setSubmenu_(submenu)
{ "menu": item }

```

---

<div class="post-metadata">

**Author:** ![SCarewe](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/scarewe/32/18952_2.png) [@SCarewe](https://forum.glyphsapp.com/u/SCarewe)\
**Post date:** [May 26, 2023, 5:59pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/5 "2023-05-26T17:59:58Z")

</div>

Thanks! Got it to work.

---

<div class="post-metadata">

**Author:** ![alexs](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@alexs](https://forum.glyphsapp.com/u/alexs)\
**Post date:** [August 29, 2025, 3:32pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/6 "2025-08-29T15:32:18Z")

</div>

May I ask how to add a submenu to the plugin’s menu this way?

 ![image](https://forum.glyphsapp.com/uploads/default/original/3X/8/c/8c8cae55f14d1cbb89d5788e9a9aa3550dd58932.jpeg)

I get the code above, but can’t figure out how to find that menu, since we define it as menuName in settings:

```auto
def settings(self):
	self.menuName = Glyphs.localize({
		'en': 'My Plugin’,
	})

```

---

<div class="post-metadata">

**Author:** ![FlorianPircher](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/florianpircher/32/30457_2.png) [@FlorianPircher](https://forum.glyphsapp.com/u/FlorianPircher)\
**Post date:** [September 1, 2025, 7:40am UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/7 "2025-09-01T07:40:12Z")

</div>

Is this a filter plug-in where you would like to add a submenu to the menu item that activates the plug-in?

---

<div class="post-metadata">

**Author:** ![GeorgSeifert](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/georgseifert/32/259_2.png) [@GeorgSeifert](https://forum.glyphsapp.com/u/GeorgSeifert)\
**Post date:** [September 1, 2025, 7:42am UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/8 "2025-09-01T07:42:41Z")

</div>

The `self.menuName` is only the default API that can be used by some plugins.

You need to get the main menu and from there drill down to the place you like to put your menu and add it yourself. I’ll send some sample code, later.

---

<div class="post-metadata">

**Author:** ![alexs](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@alexs](https://forum.glyphsapp.com/u/alexs)\
**Post date:** [September 1, 2025, 1:31pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/9 "2025-09-01T13:31:25Z")

</div>

Yes, a filter and I’d like to have a few options (apply, report, add the customParameter).

---

<div class="post-metadata">

**Author:** ![FlorianPircher](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/florianpircher/32/30457_2.png) [@FlorianPircher](https://forum.glyphsapp.com/u/FlorianPircher)\
**Post date:** [September 1, 2025, 1:44pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/10 "2025-09-01T13:44:07Z")

</div>

In that case it’s best to add a new menu item and add the submenu there. Having a submenu on the same menu item that opens the filter is fairly confusing and thus seldomly done.

---

<div class="post-metadata">

**Author:** ![alexs](https://forum.glyphsapp.com/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@alexs](https://forum.glyphsapp.com/u/alexs)\
**Post date:** [September 1, 2025, 1:51pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/11 "2025-09-01T13:51:31Z")

</div>

I mean it doesn’t open a window, just these options. Is it safe to set `self.menuName = None` and add a new menu item instead of it? Feels hacky

---

<div class="post-metadata">

**Author:** ![GeorgSeifert](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/georgseifert/32/259_2.png) [@GeorgSeifert](https://forum.glyphsapp.com/u/GeorgSeifert)\
**Post date:** [September 2, 2025, 4:26pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/12 "2025-09-02T16:26:06Z")

</div>

The general plugin has a small sample: [GlyphsSDK/Python Templates/General Plugin at Glyphs3 · schriftgestalt/GlyphsSDK · GitHub](https://github.com/schriftgestalt/GlyphsSDK/tree/Glyphs3/Python%20Templates/General%20Plugin)

But you need to dig a bit deeper:

```auto
newItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Some Name", None, "")
Glyphs.menu[PATH_MENU].submenu().itemWithTitle_("Other").append(newItem)

```

But this only works with the English localization. You can try:

```auto
newItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("Some Name", None, "")
Glyphs.menu[PATH_MENU].submenu().itemArray().lastObject().append(newItem)

```

That break if some other plugin adds an item after the “Other” item.

---

<div class="post-metadata">

**Author:** ![HugoJ](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/hugoj/32/30341_2.png) [@HugoJ](https://forum.glyphsapp.com/u/HugoJ)\
**Post date:** [September 2, 2025, 5:05pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/13 "2025-09-02T17:05:47Z")

</div>

I have something for that, I will share the code tomorrow

---

<div class="post-metadata">

**Author:** ![HugoJ](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/hugoj/32/30341_2.png) [@HugoJ](https://forum.glyphsapp.com/u/HugoJ)\
**Post date:** [September 3, 2025, 7:59am UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/14 "2025-09-03T07:59:40Z")

</div>

```python
# Create main menu item with submenu

    mainMenuItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
        "YourMenuName", None, ""
    )
  
    # Create submenu
    submenu = NSMenu.alloc().init()
  
    # Add submenu items
    subMenu1 = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
        "YourFirstSubMenu", "NameOfYourCallback", ""
    )
    subMenu1.setTarget_(self)
    submenu.addItem_(subMenu1)
  
    # Add separator
    submenu.addItem_(NSMenuItem.separatorItem())
  
    # Add submenu items
    subMenu2 = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
        "YourSecondSubMenu", "NameOfYourCallback", ""
    )
    subMenu2.setTarget_(self)
    submenu.addItem_(subMenu2)
  
    # Attach submenu to main menu item
    mainMenuItem.setSubmenu_(submenu)
  
    # Add to Glyphs menu
    Glyphs.menu[WINDOW_MENU].append(mainMenuItem)

```

---

<div class="post-metadata">

**Author:** ![michaelrafailyk](https://forum.glyphsapp.com/user_avatar/forum.glyphsapp.com/michaelrafailyk/32/32212_2.png) [@michaelrafailyk](https://forum.glyphsapp.com/u/michaelrafailyk)\
**Post date:** [October 24, 2025, 11:21pm UTC](https://forum.glyphsapp.com/t/scripting-help-add-separator-in-menu/26142/15 "2025-10-24T23:21:02Z")

</div>

> [@FlorianPircher](#):
>
> `{ "menu": NSMenuItem.separatorItem() }`

What is the best practice and convention if I need to separate the group of few items in context menu?  
– Add separators above and below the group  
– Add only one separator above, before the group

I’m thinking about the case when different plugins have context menu items with separators above and below, so separators from different plugins will make double line.
