Settings dialog for Enhanced Applets

Is it possible to enhance the Applets with a Preferences menu item or button to open a preferences dialog (maybe built with Dialog Toolkit)?

Should be. You just need a handler that will show the prefs window, then make it the action of a new Preferences menu item. Something like this:

set appMenu to (current application's NSApp's mainMenu()'s itemAtIndex:0)'s submenu()
set newItem to current application's NSMenuItem's alloc()'s initWithTitle:"Preferences…" action:"showPrefs:" keyEquivalent:""
newItem's setTarget:me
appMenu's insertItem:newItem atIndex:2


on showPrefs:sender

The tricky thing is to stop it from being added to Script Debugger’s menu when testing. You need to add some test, checking path to me or the name of current application, or something.

Thanks, Shane.

I’ll try that. How do I avoid that the Enhanced Applet starts the progress when I add a command to the run handler? The script seems only to wait for dragged items when the run handler is empty.

I fear you’re snookered. I guess you could use an appletFileIsAcceptable handler to add it after the first file is dropped. You might want to make a feature request.

Uh, I totally forgot about that. Are there any changes in the Enhanced Applet so it’s now possible to add a preferences window to an Droplet?

I don’t believe there were any changes in version 8 in that regard.

Hi Shane. Thanks for your reply. So it would be great if you can transfer this topic to a freature request. Most of my Scripts/Droplets are configurable. As I don’t want the users to modifiy scripts I’m using defaults write/read. But the users often don’t read the docs or forget about some possible settings.

It’s in the database, but I’m not sure exactly what you’re expecting.

Well, I expect an Enhanced Droplet/Applet where I have a Preferences menu item which is also reachable via Cmd+Comma. This could call a subroutine using Dialog Toolkit to provide a preferences window.

The problem is really that the idea of menu-item-driven commands just doesn’t fit in with the AppleScript approach of run and open handlers. Just adding a menu item is what the code earlier in this thread does, and as you’ve seen, it’s not the answer. Honestly, I don’t see any simple solution.

You know, if you could load a dialog toolkits alert/window into an enhanced applets window, the way you can with Display Dialog and Display Alert, that could get you partway there.

Thanks for your replies. The initial tip from Shane is great. I modified it to the following so that it works well with standard Droplets (in the run handler). So I can assign the standard menu item for preferences with a function:

if name of current application is name of me then
	set appMenu to (current application's NSApp's mainMenu()'s itemAtIndex:0)'s submenu()
	set prefsItem to appMenu's itemAtIndex:2
	prefsItem's setAction:"showPrefs:"
	prefsItem's setTarget:me
end if

This does not work in the Enhanced Droplet as the run handler breaks the Droplet window. If that could be fixed, it would be great. Or is there another handler to perform initial setup routines? The docs say something about “performSelectorOnMainThread” but how/where do I use it?

Sorry, but I can’t see any obvious solution at this stage.

Okay, good to know that I can stop the investigation now.

So my feature request will be:

  • Make the run handler work on Enhanced Droplets so it can be used for initial stuff without forcing the progress window to start / alternatively implement an init handler which will be executed once before the droplet window accepts input