I made a an AppleScript app that accepts dropped applications (it relaunches them, I need that for one of my other apps).
This works on older macOS versions (e.g. High Sierra) just fine, but I found that on Sequoia dropping apps onto the droplet won’t pass these app references to the “on open” handler. Dropping other kinds of files works, however.
I basically started a new simple droplet in SD 8 and saved it as an Application (Apple). Nothing fancy.
Any idea how to make this work? I tried signing and notarizing the app but that doesn’t make a difference.
I suspect that’s a new security feature in recent macOS versions, but I can’t find out what I need to do to make it work.
…as well as feedback FB11916431 I submitted a year later.
There I specifically indicated that the application:openFiles: app delegate method ignores applications (.app items). (The problem with the on open handler is just a consequence of the app delegate method bug.)
Apple did reply to this feedback with some useless suggestion that didn’t make any difference, to which I replied but never heard back from them.
I found a workaround for my particular case, but that’s not a universal fix:
In the “on run” handler, I check if there are file refs in the “Drag pasteboard”. That code is based on this post.
This workaround assumes that the app was launched by the drop action - if the app was already running, then it won’t get another “on run” invocation and thus won’t know that a .app was dropped onto it because the “on open” handler won’t get invoked at all then if only .app items were dropped onto it.
Also, if you just dragged some items in Finder even if you canceled that drag operation, and then double click the droplet so that its run handler is invoked, it will find the previously dragged items (because the Drag Pasteboard doesn’t get cleared) and process those, so it’s a bit unsafe to use unless you know that you mustn’t open this app without dropping items onto it, or unexpected things might happen. Good enough for my own use case, though.
Also, I reported it as a bug to Apple as well, FB21456137
Here’s the code I’m using:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property NSPasteboard : a reference to current application's NSPasteboard
property NSURL : a reference to current application's NSURL
on open theApps
-- this won't be called as expected for dropped .app items on recent macOS versions
my processApps(theApps)
end open
on run
-- Since Ventura, dropping applications onto this droplet doesn't invoke the "on open" handler any more.
-- As a work-around, we fetch the dropped items from the Drag Pasteboard
-- See also: https://www.macscripter.net/t//77616
set pbdrag to NSPasteboard's pasteboardWithName:(current application's NSPasteboardNameDrag)
set dropped_urls to (pbdrag's readObjectsForClasses:{NSURL's class} options:(missing value)) as list
my processApps(dropped_urls)
end run
on processApps(theApps)
-- handle the dropped item(s) here
end processApps