Enhanced applet questions

I have a script that I’ve saved as an apple Applet and it works just fine.

It’s also a droplet that I was thinking would be a good candidate for an enhanced applet.

When I run it as an applet it runs just fine and when it’s done it quits.

When I run it as an enhanced applet it runs just fine, but when it’s done it stays open and the user has to click a “Stop” button.

Is there a way around this? I’d prefer it to just go away when it’s done.

→ Script Debugger 8.0.2 (8A39)
→ Mac OS 11.6 (20G165)

It’s your script’s responsibility to tell an enhanced applet to quit when it’s done.

Something like this:
tell me to quit

I’m finding the Enhanced Applet pretty frustrating.

I have a script that would be a nice candidate for it and would use it’s drop file and search interfaces. But I can’t get either to work.

Also, if I drop files on it from Finder it works, executing the open handler, but when that’s done it executes the run handler. After that it stays open and the window acts as if it’s accepting dropped files, but it doesn’t execute the open handler. And the search won’t search.

If I run it executes the run handler but when finished doesn’t switch to the drag and drop/search mode. It just sits there until I quit.

Does anyone one have a sample Enhanced Applet with those features working?

→ Script Debugger: 8.0.2 (8A39)
→ Mac OS: 11.6 (20G165)

Here is a bare boned minimal attempt at an enhanced applet.

It’s working a little better after I removed most of my script, but it still has a few issues.

Run Handler:

After it runs via the run handler it stays open, but doesn’t allow me to drag and drop on the window.

In some cases I’ve seen a stop button after the run handler, but with this version there’s no button. It just looks like a progress display stuck on the first increment. Closing the window quits it.

Open handler:
After the open handler executes the first time (from the finder) it invokes the run handler.

After the open handler executes from dropping on the window it doesn’t invoke the run handler.

I have to click the quit button twice to make it quit.

Searching and dragging and dropping on the window seem fine.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

use script "FileManagerLib" version "2.3.5"

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 open filesToOpen
   set listOfFileNames to {}
   repeat with thisFile in filesToOpen
      set fileInfo to parse object thisFile ¬
         with HFS results
      set the end of listOfFileNames to name_stub of fileInfo
      
   end repeat
   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 open

on run
   
   set userChoice to display dialog ("Enhanced Droplet Test") ¬
      default answer ("Enhanced Droplet Test") ¬
      hidden answer false ¬
      buttons {"Done", "OK"} ¬
      default button 2 ¬
      cancel button 1 ¬
      with title ("Enhanced Droplet Test") ¬
   
   tell me to quit
end run

on quit
   try
      continue quit
   end try
end quit

on appletFileIsAcceptable(theFile)
   return true
end appletFileIsAcceptable

Hi Ed,

Thanks for the example. There were some issues that I’ve resolved in the just release SD 8.0.3 beta build:

These fixes should resolve the problems you experienced following the completion of the on open handler. The on run handler should no longer be invoked following the on open handler and the droplet should return to a usable state following the completion of the on open handler. The on run handler will only run when the script is launched.

Further, if you have the Stay Open application option checked, the droplet will continue running after the on open handler completes. You can do as Shane suggests and tell the app to quit if you want it to terminate. Alternatively, you can uncheck the Stay Open application option which causes the droplet to quit immiadatly after the on open handler concludes.

Hi Mark, still having issues with the new version of the enhanced applet.

Drag and drop onto the window doesn’t seem to work at all, either when it’s launched from Run or drag and drop onto the icon. The window highlights but nothing happens.

Search doesn’t work most of the time, but I was able to get it to work once.

After drag and drop onto the icon the run handler still executes.

Also there seems to be an issue with the choose from list command.

When the following executes in SD the “OK” button is highlighted when no list item is selected.

When it executes with the enhanced applet the button is not highlighted unless a list item is selected. It seems to be ignoring the “empty selection allowed” setting.

Also, at least with the script I’m converting, dragging more than two or three icons onto the enhanced applet icon doesn’t work. It highlights but doesn’t launch.

→ Script Debugger 8.0.3 (8A41)
→ Mac OS 11.6 (20G165)

	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

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.