I think this question applies to both Apple Applets and Enhanced Applets, but in using file extensions and UTIs, is it possible to have a droplet also respond to folders?
In my script if the user drops a folder (or any directory) on the icon, the script looks inside and for the right items to open.
Did you re-save your applet following the updating Script Debugger? A re-save is required to update the runtime shell that executes your script. I’m unable to reproduce this behaviour here with the current build.
Here’s a simple test I created:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
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
This runs as I would expect: the choose from list sheet appears when launched and then it goes into droplet mode.
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.