I found this code by mnoriega that adds a menu and submenus to the right hand side of the menu bar.
Here is the link:
https://macscripter.net/viewtopic.php?pid=196659
I would like to add a few menu items to the File menu of an applescript app that at present shows only one item “Use Startup Screen” and it is disabled.
If that is not possible then is it possible to have the menu on the left after the Edit menu?
Thanks in advance.
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
property theStatusItem : missing value
property BigMenu : missing value
on run
init() of me
end run
on init()
set theList to {"Fruit", {"Apple", "Banana"}, "Vegetable", {"Lettuce", "Tomato"}, "", "Quit"}
set theStatusItem to current application's NSStatusBar's systemStatusBar()'s statusItemWithLength:(current application's NSVariableStatusItemLength)
theStatusItem's setTitle:"Food"
theStatusItem's setHighlightMode:true
theStatusItem's setMenu:createMenu(theList)
end init
on createMenu(aList)
set aMenu to current application's NSMenu's alloc()'s init()
set aCount to 10
set prevMenuItem to ""
repeat with i in aList
set j to contents of i
set aClass to (class of j) as string
if j is equal to "" then
set aMenuItem to (current application's NSMenuItem's separatorItem())
(aMenu's addItem:aMenuItem)
else
if (aClass = "text") or (aClass = "string") then
if j = "Quit" then
set aMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:j action:"actionHandler:" keyEquivalent:"")
else
set aMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:j action:"actionHandler:" keyEquivalent:"")
end if
(aMenuItem's setTag:aCount)
(aMenuItem's setTarget:me)
(aMenu's addItem:aMenuItem)
set aCount to aCount + 10
copy aMenuItem to prevMenuItem
else if aClass = "list" then
--Generate Submenu
set subMenu to current application's NSMenu's new()
(aMenuItem's setSubmenu:subMenu)
set subCounter to 1
repeat with ii in j
set jj to contents of ii
set subMenuItem1 to (current application's NSMenuItem's alloc()'s initWithTitle:jj action:"actionHandler:" keyEquivalent:"")
(subMenuItem1's setTarget:me)
(subMenuItem1's setTag:(aCount + subCounter))
(subMenu's addItem:subMenuItem1)
set subCounter to subCounter + 1
end repeat
end if
end if
end repeat
return aMenu
end createMenu
on actionHandler:sender
set theTag to tag of sender as integer
set theTitle to title of sender as string
if theTitle is not equal to "Quit" then
display dialog (theTag as string) & " " & theTitle as string
else
current application's NSStatusBar's systemStatusBar()'s removeStatusItem:theStatusItem
quit
end if
end actionHandler: