I am creating a menubar app in OS X 10.10 that consists of a dynamically created dropdown menu. Depending on what is clicked on the dropdown menu, a different shell script (or in this early case, a simple display dialog) is to be run based off of the title of the item selected.
I am unable to figure out how to pass the title of the selected menu item as a string to ‘someAction:sender’. As of right now, no matter what is selected from the dropdown menu, the same action will happen every time. I would like to have a way to perform a unique action depending on what is selected without having to manually create an action for each menu item (as the number of menu items will change). How can I accomplish this?
Thank you,
Here is the section of the code in question:
on makeMenus()
....................
set dividerCount to 0
repeat with i from 1 to number of items in mylibrary
set this_item to item i of mylibrary
--display dialog this_item
set thisMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:this_item action:"someAction" keyEquivalent:"")
(newMenu's addItem:thisMenuItem)
(thisMenuItem's setTarget:me) -- required for enabling the menu item
set dividerCount to dividerCount + 1
if dividerCount is 4 then
(newMenu's addItem:(current application's NSMenuItem's separatorItem)) -- add a seperator
set dividerCount to 0
end if
end repeat
set quitMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:"Quit" action:"showQuit:" keyEquivalent:"")
StatusItem's setMenu:newMenu
newMenu's addItem:quitMenuItem
quitMenuItem's setTarget:me
end makeMenus
--menuItems action is required for the menu to be enabled
on someAction()
display dialog "THIS IS WHERE I WOULD LIKE TO DISPLAY THE TITLE OF THE MENU ITEM SELECTED"
end someAction
on showQuit:sender
quit
end showQuit: