Here is a movie that illustrates the problems. I added some code to your sample to make it clear where the issues are. I’ve also included all the Applets referenced in the movie.
These are the issues in the current version of the enhanced applet shell:
The Run handler is invoked after the open handler stops if the open handler was invoked by drag and drop on the icon in the finder. It doesn’t happen if the open handler is called from search or dropping icons on the window.
My versions of the script don’t work and I don’t know why. After they run I can’t use the search or drag and drop in the menu.
Titles don’t display in Choose From List or Display Dialog
The OK button doesn’t highlight unless a Choose From List selection is made even when empty selections allowed is true.
→ Script Debugger: 8.0.3 (8A41)
→ Mac OS: 11.6 (20G165)
And here’s another twist. In response to another question I turned on Show Startup Screen on Mark’sDemo.app and it did not execute the run handler after the open handler when Icons were dropped on it.
@alldritt : I can confirm the behavior unfortunately. In the run handler I add a preference menu handler and read the settings. The latter are not present in this case and I get an error message “The variable … is not defined.”
Would it be possible for this use case to introduce a “Load” handler that is called before all other handlers, if it is present. The Rum and Open handlers already has certain functions in an applet.
I think we can do this in plain AppleScript without introducing new handlers:
property isLoaded: false
on load()
if not isLoaded then
...
set isLoaded to true
end
end
on run
load()
...
end
on open theFiles
load()
...
end
When I resolve the bug where the on run handler is invoked after the on open handler is called, you’ll only get the on run call once. If the user launches the droplet by dropping files on it in the Finder, the on run hander is not invoked before the on open handler is invoked to handle the dropped files.
This is exactly how I solved it .
This was not possible before version 8.0.3, because the droplet state was not preserved if you had executed any code in the Run handler.
With my Versions script, if I double click the icon it launches and executes the run handler. After that it remains in an unusable state, where search and drag and drop on the window don’t work.
Also, if I drag and drop on the icon it works, and when it’s done executing I can drag and drop on the window and search works.
I still have to click the Quit button twice.
Are you in the mood for a feature request? When it’s in the search/drop state would it be possible to have another option that would invoke the run handler (or any handler, really)?
→ Script Debugger: 8.0.3 (8A42)
→ Mac OS: 11.6 (20G165)
I cannot reproduce the filature you describe with my test script:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property appletDropName : "Drag and drop files here" -- text prompt for drop tab
property appletDropImage : missing value -- name of image to appear on drop tab
property appletSearchName : "Search for files" -- text prompt for search tab
property appletSearchImage : missing value -- name of image to appear on search tab
on run
set listOfFileNames to {1, 2, 3, 4, 5, 6}
set userChoice to choose from list listOfFileNames ¬
with title ("Enhanced Droplet Test") ¬
with prompt ("List of names of files in open handler") ¬
default items 1 ¬
OK button name ("OK") ¬
cancel button name ("Done") ¬
multiple selections allowed true ¬
with empty selection allowed
end run
on open theFiles
beep
end open
on quit
try
continue quit
end try
end quit
on appletFileIsAcceptable(theFile)
return true
end appletFileIsAcceptable
When I launch the script it runs and then I can drop files.
I saved your script as is. When run after it runs it’s in the Drop/search mode.
If I drop an Icon on the window it works.
Search doesn’t work.
If I change the Bundle & Export settings, adding scptd and app save and quit the script, then when I run the script it runs but when I drop an icon on the window it doesn’t work. Search doesn’t work either.
In both cases, if I launch it by dropping an icon on it’s icon it works, and after it executes Search and Drag and Drop on the window doesn’t work.
I have an enhanced applet that controls several apps including Pages.
After using it for a few weeks with no issues I added a UI command to select a menu item in Pages. Works just fine in SD, but in Enhanced App it failed saying the app didn’t have permission to control the mac, and it took me to the accessibility pane in the General Settings preferences. There was a list of apps that had been given permission to control the mac and a + button to add an app. I clicked the + and navigated to the enhanced app but it did not appear in the navigation dialog. The Apple applet in the same folder was there.
So then I saved the enhanced app as an Apple pplet, and tried to run that, and got the same dialog, but the newly saved applet was in the navigation window so I added that.
Here’s the weird thing. I then tried to run the enhanced applet version and this time it worked. The GUI stuff worked and the app name still isn’t listed in the accessibility pane. The bundle IDs and app names are different.
I don’t know if it’s a new issue or not (I rarely use GUI stuff) and don’t know if it’s related to SD version or OS version or something else.
Either way it seems to work and it’s not an applet I’m likely to distribute so my issue solved itself, I just don’t know how.