adding menu items to the right click app menu in the dock casues them to be re-added each time i clickWhen to remove dynamic NSMenuItem's from an NSMenuHow to create a menu when a user right-clicks on the dock-icon of cocoa app on Mac?Cocoa osx: Add a menu item on dock elements for all running applicationsAdd a menu item for OS X Trash dock menuMenu items don't appear in nibless StatusMenu app?JXA Creating an app delegate causes app to crashApplication Dock Menu with image on menu itemAdding item to Contextual menu and send highlighted text to other app on MacOSwhy does NSApplication sharedApplication mainMenu return nil?macOS: Add commands to existing application right-click menu in dockCreate a menu inside of a view (macos, cocoa, swift)?

How do I subvert the tropes of a train heist?

Uses of T extends U?

Which noble houses were destroyed during the Game of Thrones?

How can I find where certain bash function is defined?

Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?

Is there any use case for the bottom type as a function parameter type?

File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell

Mother abusing my finances

Is a post-climate apocolypse city in which many or most insects have disappeared realistic?

What are the benefits of cryosleep?

Yandex Programming Contest: Alarms

How can I prevent interns from being expendable?

I think I may have violated academic integrity last year - what should I do?

How to capture more stars?

What is a subpixel in Super Mario Bros, and how does it relate to wall clipping?

Leading and Suffering Numbers

How to extract lower and upper bound in numeric format from a confidence interval string?

Black-and-white film where monster/alien gets fried

Is it ok to put a subplot to a story that is never meant to contribute to the development of the main plot?

If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?

Plot exactly N bounce of a ball

What does "Marchentalender" on the front of a postcard mean?

Restoring order in a deck of playing cards

Future enhancements for the finite element method



adding menu items to the right click app menu in the dock casues them to be re-added each time i click


When to remove dynamic NSMenuItem's from an NSMenuHow to create a menu when a user right-clicks on the dock-icon of cocoa app on Mac?Cocoa osx: Add a menu item on dock elements for all running applicationsAdd a menu item for OS X Trash dock menuMenu items don't appear in nibless StatusMenu app?JXA Creating an app delegate causes app to crashApplication Dock Menu with image on menu itemAdding item to Contextual menu and send highlighted text to other app on MacOSwhy does NSApplication sharedApplication mainMenu return nil?macOS: Add commands to existing application right-click menu in dockCreate a menu inside of a view (macos, cocoa, swift)?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















so i've been trying to add items to the right click menu
when u right click on the app icon in the dock in macos



but when i do it with this code whenver i right click the app icon
it re-adds the menu item



 class myclass: NSObject , NSApplicationDelegate{


func applicationDockMenu(_ sender: NSApplication) -> NSMenu?


dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")

return dockMenu



enter image description here










share|improve this question
























  • where is your dockMenu defined?

    – Amir Khan
    Mar 24 at 8:48











  • @AmirKhan outside of myclass as "let dockMenu = NSMenu()"

    – bibble triple
    Mar 24 at 8:52












  • Follow this link - stackoverflow.com/questions/6817214/…

    – Amir Khan
    Mar 24 at 8:58











  • @vadian if i do that i cant acees the menu item from outside of that function

    – bibble triple
    Mar 24 at 9:06











  • try to remove all menu items before adding new items.

    – Amir Khan
    Mar 24 at 9:07

















0















so i've been trying to add items to the right click menu
when u right click on the app icon in the dock in macos



but when i do it with this code whenver i right click the app icon
it re-adds the menu item



 class myclass: NSObject , NSApplicationDelegate{


func applicationDockMenu(_ sender: NSApplication) -> NSMenu?


dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")

return dockMenu



enter image description here










share|improve this question
























  • where is your dockMenu defined?

    – Amir Khan
    Mar 24 at 8:48











  • @AmirKhan outside of myclass as "let dockMenu = NSMenu()"

    – bibble triple
    Mar 24 at 8:52












  • Follow this link - stackoverflow.com/questions/6817214/…

    – Amir Khan
    Mar 24 at 8:58











  • @vadian if i do that i cant acees the menu item from outside of that function

    – bibble triple
    Mar 24 at 9:06











  • try to remove all menu items before adding new items.

    – Amir Khan
    Mar 24 at 9:07













0












0








0








so i've been trying to add items to the right click menu
when u right click on the app icon in the dock in macos



but when i do it with this code whenver i right click the app icon
it re-adds the menu item



 class myclass: NSObject , NSApplicationDelegate{


func applicationDockMenu(_ sender: NSApplication) -> NSMenu?


dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")

return dockMenu



enter image description here










share|improve this question
















so i've been trying to add items to the right click menu
when u right click on the app icon in the dock in macos



but when i do it with this code whenver i right click the app icon
it re-adds the menu item



 class myclass: NSObject , NSApplicationDelegate{


func applicationDockMenu(_ sender: NSApplication) -> NSMenu?


dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")

return dockMenu



enter image description here







swift macos cocoa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 8:53









a.masri

1,8371825




1,8371825










asked Mar 24 at 8:44









bibble triplebibble triple

65




65












  • where is your dockMenu defined?

    – Amir Khan
    Mar 24 at 8:48











  • @AmirKhan outside of myclass as "let dockMenu = NSMenu()"

    – bibble triple
    Mar 24 at 8:52












  • Follow this link - stackoverflow.com/questions/6817214/…

    – Amir Khan
    Mar 24 at 8:58











  • @vadian if i do that i cant acees the menu item from outside of that function

    – bibble triple
    Mar 24 at 9:06











  • try to remove all menu items before adding new items.

    – Amir Khan
    Mar 24 at 9:07

















  • where is your dockMenu defined?

    – Amir Khan
    Mar 24 at 8:48











  • @AmirKhan outside of myclass as "let dockMenu = NSMenu()"

    – bibble triple
    Mar 24 at 8:52












  • Follow this link - stackoverflow.com/questions/6817214/…

    – Amir Khan
    Mar 24 at 8:58











  • @vadian if i do that i cant acees the menu item from outside of that function

    – bibble triple
    Mar 24 at 9:06











  • try to remove all menu items before adding new items.

    – Amir Khan
    Mar 24 at 9:07
















where is your dockMenu defined?

– Amir Khan
Mar 24 at 8:48





where is your dockMenu defined?

– Amir Khan
Mar 24 at 8:48













@AmirKhan outside of myclass as "let dockMenu = NSMenu()"

– bibble triple
Mar 24 at 8:52






@AmirKhan outside of myclass as "let dockMenu = NSMenu()"

– bibble triple
Mar 24 at 8:52














Follow this link - stackoverflow.com/questions/6817214/…

– Amir Khan
Mar 24 at 8:58





Follow this link - stackoverflow.com/questions/6817214/…

– Amir Khan
Mar 24 at 8:58













@vadian if i do that i cant acees the menu item from outside of that function

– bibble triple
Mar 24 at 9:06





@vadian if i do that i cant acees the menu item from outside of that function

– bibble triple
Mar 24 at 9:06













try to remove all menu items before adding new items.

– Amir Khan
Mar 24 at 9:07





try to remove all menu items before adding new items.

– Amir Khan
Mar 24 at 9:07












1 Answer
1






active

oldest

votes


















0














You have to create the NSMenu inside the method



func applicationDockMenu(_ sender: NSApplication) -> NSMenu? 

let dockMenu = NSMenu()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



or remove the items



let dockMenu = NSMenu()

func applicationDockMenu(_ sender: NSApplication) -> NSMenu?

dockMenu.removeAllItems()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



However I would declare it in Interface Builder and use an outlet.






share|improve this answer

























  • if i put the let var in that function then i cant acess the menu items from outside of it

    – bibble triple
    Mar 24 at 9:16











  • See my update and please read my last sentence.

    – vadian
    Mar 24 at 9:16






  • 1





    @AmirKhan let is correct as NSMenu is reference type

    – vadian
    Mar 24 at 9:20











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322034%2fadding-menu-items-to-the-right-click-app-menu-in-the-dock-casues-them-to-be-re-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You have to create the NSMenu inside the method



func applicationDockMenu(_ sender: NSApplication) -> NSMenu? 

let dockMenu = NSMenu()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



or remove the items



let dockMenu = NSMenu()

func applicationDockMenu(_ sender: NSApplication) -> NSMenu?

dockMenu.removeAllItems()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



However I would declare it in Interface Builder and use an outlet.






share|improve this answer

























  • if i put the let var in that function then i cant acess the menu items from outside of it

    – bibble triple
    Mar 24 at 9:16











  • See my update and please read my last sentence.

    – vadian
    Mar 24 at 9:16






  • 1





    @AmirKhan let is correct as NSMenu is reference type

    – vadian
    Mar 24 at 9:20















0














You have to create the NSMenu inside the method



func applicationDockMenu(_ sender: NSApplication) -> NSMenu? 

let dockMenu = NSMenu()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



or remove the items



let dockMenu = NSMenu()

func applicationDockMenu(_ sender: NSApplication) -> NSMenu?

dockMenu.removeAllItems()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



However I would declare it in Interface Builder and use an outlet.






share|improve this answer

























  • if i put the let var in that function then i cant acess the menu items from outside of it

    – bibble triple
    Mar 24 at 9:16











  • See my update and please read my last sentence.

    – vadian
    Mar 24 at 9:16






  • 1





    @AmirKhan let is correct as NSMenu is reference type

    – vadian
    Mar 24 at 9:20













0












0








0







You have to create the NSMenu inside the method



func applicationDockMenu(_ sender: NSApplication) -> NSMenu? 

let dockMenu = NSMenu()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



or remove the items



let dockMenu = NSMenu()

func applicationDockMenu(_ sender: NSApplication) -> NSMenu?

dockMenu.removeAllItems()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



However I would declare it in Interface Builder and use an outlet.






share|improve this answer















You have to create the NSMenu inside the method



func applicationDockMenu(_ sender: NSApplication) -> NSMenu? 

let dockMenu = NSMenu()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



or remove the items



let dockMenu = NSMenu()

func applicationDockMenu(_ sender: NSApplication) -> NSMenu?

dockMenu.removeAllItems()
dockMenu.addItem(withTitle: "test1", action: nil, keyEquivalent: "")
return dockMenu



However I would declare it in Interface Builder and use an outlet.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 9:15

























answered Mar 24 at 9:02









vadianvadian

161k17175196




161k17175196












  • if i put the let var in that function then i cant acess the menu items from outside of it

    – bibble triple
    Mar 24 at 9:16











  • See my update and please read my last sentence.

    – vadian
    Mar 24 at 9:16






  • 1





    @AmirKhan let is correct as NSMenu is reference type

    – vadian
    Mar 24 at 9:20

















  • if i put the let var in that function then i cant acess the menu items from outside of it

    – bibble triple
    Mar 24 at 9:16











  • See my update and please read my last sentence.

    – vadian
    Mar 24 at 9:16






  • 1





    @AmirKhan let is correct as NSMenu is reference type

    – vadian
    Mar 24 at 9:20
















if i put the let var in that function then i cant acess the menu items from outside of it

– bibble triple
Mar 24 at 9:16





if i put the let var in that function then i cant acess the menu items from outside of it

– bibble triple
Mar 24 at 9:16













See my update and please read my last sentence.

– vadian
Mar 24 at 9:16





See my update and please read my last sentence.

– vadian
Mar 24 at 9:16




1




1





@AmirKhan let is correct as NSMenu is reference type

– vadian
Mar 24 at 9:20





@AmirKhan let is correct as NSMenu is reference type

– vadian
Mar 24 at 9:20



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322034%2fadding-menu-items-to-the-right-click-app-menu-in-the-dock-casues-them-to-be-re-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript