My applet’s UI is an enhanced window created with Shane Stanley’s DTP v1.1.3. It currently has a “Quit” button which is used to do some clean up and quit the applet [with an error number -128]. I need a new button to go into the space taken by the Quit button. So, I have been trying to enable the “Quit” menu item, which is greyed out.
First idea I tried was to add this to the DTP library in the showTheWindowAndWaitMainThread handler:
That crashes with: “[NSMenultem validateMenultem]: unrecognized selector sent to instance”.
Another option would be to get the DTP library to report back that the window was closed and treat that as a quit. But, I have two questions: Why is the Quit menu item disabled for an AppleScript applet and is there a way to enable it or any other disabled menu item ?
Model: Mac Studio Max 32GB 24c (Ventura)
Browser: Safari 16.1 (18622.214.171.124.12)
Operating System: macOS 12
I can’t figure how to make it work. I’m really not sure what “target” and “action” mean. But, I’ve tried a variety of code ideas all of which fail “unrecognized selector sent to instance”. My final attempt was this:
set appMenu to (current application's NSApp's mainMenu()'s itemAtIndex:0)'s submenu()
set menuItem to appMenu's itemAtIndex:6
And elsewhere I added:
if name of current application does not start with "Script" then tell me to quit
Googling has revealed a lot of examples and ideas none of which worked. There must be a way to get Quit menu item working but, I can’t find it.
Apple’s programming language and many others use a software pattern called MVC.
It stands for Model-View-Controller.
You could google: MVC
In simple terms:
Model could be a database, storage or data of some kind
View is what the user see on the screen, it could contents buttons, sliders…
Controller perform events or actions to communicate with the view or the model
Why is this important, it will help you to understand how a application works.
Action is a selector and in ASObjC its a string + “:” at the end.
You need a action handler
if name of current application does not start with “Script” then tell me to quit
I’m still trying to understand why the ‘Quit’ menu item is disabled in an applet in the first place.
In every applet I have/create, the menu item ‘Quit’ works just fine.
Along with a ‘on quit’ handler in my stay-open applet, it works fine.
What kind of applet is this that the standard ‘Quit’ is greyed out?