I know this question has been asked many times but it seems no better solution for it.
Changing the allowsUserCustomization
property doesn't help. It seems there is no API to customize the items in toolbar's context menu.
Finder app has no "Use Small Size" while Notes app has only "Customize Toolbar.."
I would like to know if there is any way to subclass or extend or do whatever to the NSToolbar to achieve the purpose?
Updated 1:
According to @Khundragpan and this post, problem 1 can be solved by:
if let contextMenu = window?.contentView?.superview?.menu {
for item in contextMenu.items {
if item.title != "Customize Toolbar…" {
contextMenu.removeItem(item)
}
}
}
But I don't think it's the best way.
Update 2:
Another way to solve problem 1 (thanks to @1024jp to point out this file):
if let contextMenu = window?.contentView?.superview?.menu {
contextMenu.items.forEach({ (item) in
if let action = item.action,
NSStringFromSelector(action) != "runToolbarCustomizationPalette:" {
contextMenu.removeItem(item)
}
})
}
Update 3:
A ton of thanks to @1024jp for helping me. I'm able to remove those things with a few tips and tricks from him. Check the answer below.