Another Drag & Drop question

Hi folks,

We have a little in-house app that is registering drag & drop events to its app bundle for certain file types.

But I’m struggling to also have an ImageView work in a similar fashion.

I do have something along the lines of https://macscripter.net/viewtopic.php?pid=165338#p165338 logging back the URL of the dragged object, but I need to pass this back to my “AppDelegate.applescript” & therefore ticket the following:

on |application|:theApp openFile:aFile
    theWindow's makeKeyAndOrderFront_(null)
    if openOnce
        resetValues_(me)
    end if
    delay 0.1
    set my startEnabled to false
    set my textEnabled to true
    validateButton's setKeyEquivalent:"\r"
    set aFile to aFile as text
    set my aFile to aFile as text
    log "file: " & aFile
    set my fileType to do shell script "/usr/bin/mdls " & quoted form of aFile & " -name kMDItemContentType | /usr/bin/awk -F'\"' '{ print $2 }'" as text
        log "type: " & fileType
    set my fileName to do shell script "/usr/bin/mdls " & quoted form of aFile & " -name kMDItemDisplayName | /usr/bin/awk -F'\"' '{ print $2 }'" as text
    log "name : " & fileName
        set my pkgLabel to fileName
        set my openOnce to true
    if fileType equals "com.apple.application-bundle"
        set my fileType to "app"
        set my appName to fileName as text
        tidyName_(aFile, appName, fileType)
    else if fileType equals "com.apple.installer-package"
        set my fileType to "pkg"
        set my appName to text 1 thru -5 of fileName
        tidyName_(aFile, appName, fileType)
    else if fileType contains "com.apple.installer-package-archive"
        set my fileType to "pkg-archive"
        set my appName to text 1 thru -5 of fileName
        tidyName_(aFile, appName, fileType)
    else if fileType contains "public.folder"
        set my fileType to "folder" as text
        set my appName to fileName as text
        tidyName_(aFile, appName, fileType)
    else
        set errMsg to "open: please drag an app, pkg or folder containing applications"
        log errMsg
        userNotify_(errMsg)
    end if
end

TIA!

I think I may have had success, amending https://macscripter.net/viewtopic.php?pid=165338#p165338 as per:

script DragAndDrop
    
    property parent: class "NSImageView"
    
    on draggingEntered_(sender)
        set pb to sender's draggingPasteboard()
        set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
        return pb's canReadObjectForClasses_options_({current application's|NSURL|}, theOptions)
    end draggingEntered_
    
    on performDragOperation_(sender)
        -- Get the file path
        set pb to sender's draggingPasteboard()
        set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
        set imageURLs to pb's readObjectsForClasses_options_({current application's |NSURL|}, theOptions)
        set draggedURL to item 1 of (imageURLs as list)
        set filePath to (POSIX path of draggedURL)
        tell current application's NSApp's delegate() to |application|:current application openFile:filePath
        return true -- otherwise it doesn't happen
    end performDragOperation_
    
end script

Seems to have passed through what I need.

Shame I cannot seem to limit what is dragged, but that’s a minor pain.

The above appears to be able to be cut down a little for my use case:

script DragAndDrop
    
    property parent: class "NSImageView"
    
    on draggingEntered_(sender)
        set pb to sender's draggingPasteboard()
        set theOptions to {NSPasteboardURLReadingFileURLsOnlyKey:1}
        return pb's canReadObjectForClasses_options_({current application's|NSURL|}, theOptions)
    end draggingEntered_
    
    on performDragOperation_(sender)
        set pb to sender's draggingPasteboard()
        set filePath to pb's propertyListForType:current application's NSFilenamesPboardType
        tell current application's NSApp's delegate() to |application|:current application openFile:filePath
        return true
    end performDragOperation_
    
end script