How Can I Automate Dragging and Dropping a Finder Selection?

Here is my use case:

  • I have tens of thousands of sound files which are encoded in a proprietary format and I need to update the attributes (instruments, categories, tags, author) within them. However, I do not have access to how the files are encoded.

  • Many years ago, the creator of the file format made a utility that allows you to update the attributes without divulging the encoding scheme.

  • The utility is very basic. Its UI consists of a single window with editable text fields for the four attributes. There are no menus, buttons or even an "Open file" command. All it does is re-encode any files (one or many) dropped onto its window but replacing the file's existing sound attributes with any you typed in.

  • I have a table in a SQLite database where each row contains a filename, file path and the new attributes I have defined for each file.

  • I created a KM macro that iterates through the rows in the table. Every time any of the attributes change from one row to the next, the macro pauses, opens a finder window and selects the set of files between the previous and current change.

  • The macro then populates the editable fields in the utility with the new attributes.

  • At this point, I have to manually drag the selected files from the finder and drop them onto the utility so they can be updated with the new attributes.

  • Once I do this, I press continue and the KM macro resumes processing rows until the next change, etc.

I suspect this utility was written using the JUCE framework which forgoes standard MacOS programming toolkits for the sake of cross-platform development. This means that standard AppleScript type commands will not work.

So, can anyone suggest a way to automate the last piece of the puzzle which is to drag and drop any files selected in the foreground Finder window and drop them onto the utility's window?


The way I do this is to target Finder's highlight colour in column view and a found image in the app to drag to. Here's an example using Batchmod:

Drag and Drop from Finder.kmmacros (60.4 KB)

Macro Screenshot

Video Demo

CleanShot 2022-08-11 at 09.43.21

Setup: Replace the app name and found images in the magenta actions. Adjust pauses as desired.

Note that we have to simulate ⌘Tab rather than use the Activate Application action, because KM can't keep holding the mouse button if we do (I'm sure @peternlewis has good reason for that). Hopefully this is enough to get you going.

1 Like

Excellent. Thanx. I will give it a shot.

Update: Thank You. Worked a treat.

1 Like

This helped me as well! But a question...

I've got this dragging a folder from the Finder into Safari, specifically a Google Drive location. My problem is, the drag-drop happens so quickly that GDrive doesn't reliably detect it, so the folder doesn't upload.

Is there any way to pause before releasing the mouse?

[ummm… oops. Look at the macro screenshot.]

The macro above already pauses before releasing the mouse. Try increasing the pause length.

LOL… oh, my goodness. Now I’m embarrassed. I was so focused on the bit about using a swatch of my highlight color for a found-image action that I glossed over the specifics of your implementation.

Got it. :grimacing: and thanks for your patience.

1 Like