Enhanced applet questions

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.

For the test script and the applet I’ve been working on I pasted the script into a new document and saved as an enhanced app.

I’ll try the sample you provided.

If I still see issues I’ll post the files and a movie.

This ain’t right, Mark.

Your open handler is calling the Run handler. They should be separate, as they have been in previous Enhanced Applets and in Apple’s applet.

Files drag and dropped on the icon or in the window should simply cause it to beep and not invoke the run handler.

That should behave the same way as dragging files onto the UI.

Another thing I just noticed is that the title for the Choose From list dialog doesn’t display anywhere.

Other than that, it seems to be working better.

https://caltimes-my.sharepoint.com/:u:/g/personal/ed_stockly_latimes_com/Ef5zC0LETVpPgWc21KCM69UBTUpoeeU450PiSVZyGPlbvA?e=h3sHZU

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.

1 Like

Please see the 8A42 build:

This is exactly how I solved it :wink:.
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.

Thanks again for the changes in version 8.0.3!

Definitely progress, but still a couple issues.

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.

Thanks Mark, Dialog Toolkit seems to work well. That’s great. I considered using it but first I wanted to start simple. So, that was a bad idea. :smile:

@estockly Do you use the Beta 8.0.3? In 8.0.2 it does not work.

There are more improvements to Enhanced Applets in the Script Debugger 8.0.3 8A46 build.

So far, so good!

I’ve duplicated each of the test apps and they seem to work fine. Next I’ll try the full application.

Thanks

→ Script Debugger 8.0.3 (8A46)
→ Mac OS 11.6.1 (20G224)

This seems to have resolved all the issues. Very cool.

But I do have one question. Did the “Quit” button used to appear when the window was in drop mode?

I see it in search mode, but not drop mode.

(If not, it may be better to have it there too so the user doesn’t have to switch modes to quit)

→ Script Debugger 8.0.3 (8A46)
→ Mac OS 11.6.1 (20G224)

The quit button never appeared in the drop window. I’ll file a note at our end, but there is always the menu command to quit the app.

Got it, I figured that out eventually.

Seems that all the issues have been resolved.

3 posts were split to a new topic: Identifying Enhaced Applets