I have a couple of AppleScript apps that stays in the menu tray and I want its app icon not to appear on the dock. I tried following the solution in this old post (10yrs ago) but it no longer works, it throws a security error that I couldn't resolve via System Preferences settings.
Here is the error:
Not authorized to send Apple events to System Events.
Not authorized to send Apple events to System Events. (-1743)
Surprisingly, when I did a small quick one, it worked.
use framework "Foundation"
use framework "AppKit"
use scripting additions
property StatusItem : missing value
property selectedMenu : ""
property defaults : class "NSUserDefaults"
property internalMenuItem : class "NSMenuItem"
property externalMenuItem : class "NSMenuItem"
property newMenu : class "NSMenu"
makeStatusBar()
makeMenus()
on makeStatusBar()
set bar to current application's NSStatusBar's systemStatusBar
set StatusItem to bar's statusItemWithLength:-1.0
-- set up the initial NSStatusBars title
StatusItem's setTitle:"poc"
-- set up the initial NSMenu of the statusbar
set newMenu to current application's NSMenu's alloc()'s initWithTitle:"Custom"
newMenu's setDelegate:me
StatusItem's setMenu:newMenu
end makeStatusBar
on makeMenus()
newMenu's removeAllItems() -- remove existing menu items
set thisMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:"Quit" action:("quitAction:") keyEquivalent:"")
(newMenu's addItem:thisMenuItem)
(thisMenuItem's setTarget:me) -- required for enabling the menu item
end makeMenus
on idle
log "test"
end idle
on quitAction:sender
quit me
end quitAction:
I guess my next step is to add the functionality one at a time to figure out which statement is triggering the problem.